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

3

16

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>
Villager answered 2/3, 2010 at 12:9 Comment(1)
Related Post: #1192441Scholasticism
A
5

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

Altogether answered 2/3, 2010 at 12:13 Comment(5)
Sorry I dont understand it. I can not write nor being an admin user. And the customers not want disable UAC.Villager
Well even if you're logged on as administrator you normally don't have all admin privileges. That is the concept of UAC. You do have the same behavior when you want to manually delete a file somewhere in "Program Files". But if you run your application as admin (start with "Run as administrator...) you can delete/create files in that folder. You can also force your application to be running as admin via the manifest file.Altogether
Ok, then, in my app.manifest file, I need to insert this code "<requestedExecutionLevel level="highestAvailable" uiAccess="false" />" instead of "<requestedExecutionLevel level="asInvoker" uiAccess="false" />"?Villager
More like "<requestedExecutionLevel level="requireAdministrator"/>. Also see: petesbloggerama.blogspot.com/2007/04/… for example.Altogether
Along with the above comments, I also have set the permission to FullTrust as this: <applicationRequestMinimum> <defaultAssemblyRequest permissionSetReference="FullTrust" /> <PermissionSet version="1" ID="FullTrust" Unrestricted="true" /> </applicationRequestMinimum>Cacie
C
8

An easy to understand explanation of the different places you can store program data can be found here:

http://blogs.msdn.com/cjacks/archive/2008/02/05/where-should-i-write-program-data-instead-of-program-files.aspx

As regards ProgramData, it says:

FOLDERID_ProgramData / System.Environment.SpecialFolder.CommonApplicationData The user would never want to browse here in Explorer, and settings changed here should affect every user on the machine. The default location is %systemdrive%\ProgramData, which is a hidden folder, on an installation of Windows Vista. You'll want to create your directory and set the ACLs you need at install time.

Connelly answered 2/3, 2010 at 12:17 Comment(1)
About "You'll want to create your directory and set the ACLs you need at install time." How I can do it?Villager
A
5

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

Altogether answered 2/3, 2010 at 12:13 Comment(5)
Sorry I dont understand it. I can not write nor being an admin user. And the customers not want disable UAC.Villager
Well even if you're logged on as administrator you normally don't have all admin privileges. That is the concept of UAC. You do have the same behavior when you want to manually delete a file somewhere in "Program Files". But if you run your application as admin (start with "Run as administrator...) you can delete/create files in that folder. You can also force your application to be running as admin via the manifest file.Altogether
Ok, then, in my app.manifest file, I need to insert this code "<requestedExecutionLevel level="highestAvailable" uiAccess="false" />" instead of "<requestedExecutionLevel level="asInvoker" uiAccess="false" />"?Villager
More like "<requestedExecutionLevel level="requireAdministrator"/>. Also see: petesbloggerama.blogspot.com/2007/04/… for example.Altogether
Along with the above comments, I also have set the permission to FullTrust as this: <applicationRequestMinimum> <defaultAssemblyRequest permissionSetReference="FullTrust" /> <PermissionSet version="1" ID="FullTrust" Unrestricted="true" /> </applicationRequestMinimum>Cacie
C
0

it is a conceptual issue at first look:

You should NOT use the "ProgramData" directory but some user specific files. Needed installation data should installed in the "program files" or in the registry.

Chaparral answered 3/5, 2013 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.