.netuacwindows-vistaprogramdata

Write in "ProgramData" folder (W7 and Vista) .NET


I install my app under "Program Files" directory. And I install data, under "ProgramData" directory:

Environment.SpecialFolder.CommonApplicationData

In programData I have created folder to save data. Example:

C:\ProgramData\MyApp\MyData\here I have files and folders

Under XP all runs fine. But not under Vista or W7 OS.

I can read files in this directory, but I can not write files, I can not create new files, etc. The user is logged as Admin.

Where I can store data without restrictions? I need store data in a folder visible for all users

EDITED:

I have this code in my app.manifest file:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- Opciones del manifiesto de Control de cuentas de usuario
             Si desea cambiar el nivel de Control de cuentas de usuario de Windows, reemplace el 
             nodo requestedExecutionLevel por alguno de los siguientes.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Si desea utilizar la virtualizaciĆ³n de archivos y del Registro para la compatibilidad 
            con versiones anteriores, elimine el nodo requestedExecutionLevel.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

Solution

  • This is a UAC thing. You have your program run as administrator for creating/deleting files/folders in this SpecialFolder.