none
C:\ProgramData\CompanyName folder does not have Modify permission for power users RRS feed

  • Question

  • Hi,

    Our application creates the folder (say CompanyName folder) in C:\ProgramData folder and puts the config file in that folder during the installation. And the application modifies the file for some setting during exiting the application.

    In Windows 10, when we install the application using domain user which is administrator of the machine, the owner of C:\ProgramData\ CompanyName folder is administrator of machine. Now when we try to login the application using domain user which is power user of the machine, and launch the application, it is not able to modify the config file showing the access denied error for C:\ProgramData\ CompanyName folder.

    When I give the Modify right to C:\ProgramData\ CompanyName folder to group of domain user, I am able to modify the config file while exiting the application and access denied error does not displayed.

    In the application, to create the C:\ProgramData\ CompanyName folder, I used SecurityIdentifier class with WellKnownSidType.WorldSid option so that the created folder is accessible to all users. Also, I am initializing the FileSystemAccessRule with write, read and execute and modify rights. Still I need to specifically give the Modify right for the power users.

    Can I achieve this via code so I don’t need to give the manual Modify right to power user?


    • Edited by Hrushi17 Tuesday, May 30, 2017 10:19 AM
    Tuesday, May 30, 2017 10:16 AM

All replies

  • The problem is that this is not the correct folder for saving user-specific configuration files.

    Change the code so that editable config files are stored in the user's AppData directory.  Use My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData or My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData to get the path to the data directory for the current version of the application.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Proposed as answer by Devon_Nullman Tuesday, May 30, 2017 1:58 PM
    Tuesday, May 30, 2017 1:03 PM
    Moderator
  • Hi,

    Thanks for your reply.

    Actually the configuration file which I am storing at C:\ProgramData\CompanyName folder is same for all the users of that machine. But when user exists the application, I need to modify some settings like size and user etc. in the config file. I observed that My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData gives the path as BasePath\CompanyName\ProductName\Version. But  this config file is used by other product of our company also. So we selected the path as C:\ProgramData\CompanyName.
    I tried creating the config file with FileSystemRights.FullControl but still it is not accessible to power user unless I manually give the Modify rights.
    Can we achieve giving Modify rights to power user via code?

    Thanks,

    Hrushikesh Pande


    Hrushikesh Pande

    Thursday, June 1, 2017 6:12 AM
  • Hi Hrushi17,

    There is a discussion about modifying power user rights, please refer to :

    https://stackoverflow.com/questions/7288444/how-to-give-read-write-permissions-to-a-folder-during-installation-using-net

    Hope it is helpful to you.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 1, 2017 7:44 AM
    Moderator
  • Hi,

    Really sorry for the late reply. I figured out the actual problem. The code in which I used SecurityIdentifier class to give rights to all user is working as expected.
    The problem is, when our application used below code to create the config file when no any config file is present in ProgramData, it does not give the access permission to all the user like the SecurityIdentifier class:

     

    config =

    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

    So, now I want that when the config file is created using above code (i.e. OpenExeConfiguration(ConfigurationUserLevel.None)), how it can get the access/read/write and modify rights for everyone?

    Thanks


    Hrushikesh Pande

    Monday, June 12, 2017 9:32 AM