locked
Access Denied when accessing a file in ProgramData RRS feed

  • Question

  • Hi,

    I want to store some data 1 string and a bool and i want all the users at that machine to be able to read/write that file(mostly read). I try to access it but i get access denied. Is there any way to store that data even at registry and be able to access it from all the users in that machine without having to set my application to start with admin rights everytime? I know this is probably not the right place but i'd like to see some code if i can bypass it somehow. By the way the data are vital for the program to execute and every user has to be able to access the data.

    Friday, March 16, 2018 2:13 PM

Answers

All replies

  • Check the permissions. Program Data should be writeable for standard users.
    Friday, March 16, 2018 3:34 PM
  • You should definitely use the SpecialFolder enum. Also, your data should be in a subdirectory under ProgramData. So your path should be something like this:

    string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MyAppName");


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, March 16, 2018 3:46 PM
  • Changed the permissions but still i get access denied. Even when reading the file i get access denied
    Friday, March 16, 2018 3:49 PM
  • Thats exactly what i did BonnieB
    Friday, March 16, 2018 3:51 PM
  • Take a look at this link (I haven't had time to verify how well it works):

    https://www.codeproject.com/Tips/61987/Allow-write-modify-access-to-CommonApplicationData


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, March 16, 2018 3:55 PM
  • The post a concise and complete example.

    Friday, March 16, 2018 3:56 PM
  • Thank you very much that works flawlessly!
    Friday, March 16, 2018 4:11 PM
  • Changed the permissions but still i get access denied. Even when reading the file i get access denied
    If user/machinename/users doesn't have the permissions on the resource, then you can have permission issues.
    Friday, March 16, 2018 5:15 PM
  • If user/machinename/users doesn't have the permissions on the resource, then you can have permission issues.
    No it actually works now, i'm guessing i forgot to manually configure one of the permissions. But even if i did that, i had to do it via code and the solution above does exactly that.
    Friday, March 16, 2018 5:39 PM
  • I'm glad I could help you, Konstantinos!   =0)


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, March 16, 2018 5:48 PM
  • If user/machinename/users doesn't have the permissions on the resource, then you can have permission issues.

    No it actually works now, i'm guessing i forgot to manually configure one of the permissions. But even if i did that, i had to do it via code and the solution above does exactly that.

    Myself, I would have just used the Everyone group on the resource and give the group the needed permissions. You could have also used the Authenticated User group too.

    Friday, March 16, 2018 9:35 PM