none
how to give full-control (to everyone) to folder in C# RRS feed

  • Question

  • hi

    how to give full-control (to everyone) to any  folder in C#

    for example: i need to give full-control read,write for everyone in folder c:\Program Files\MyFolder

    is it possible ?

    thanks,

    Monday, March 25, 2013 8:46 AM

Answers

  • Hi,

    you can do this by using DirectorySecurity from namespace System.Security.AccessControl:

    DirectorySecurity ds = Directory.GetAccessControl(@"C:\test");
    ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
    Directory.SetAccessControl(@"C:\test", ds);


    Bilhan silva

    • Marked as answer by E_gold Tuesday, March 26, 2013 7:23 AM
    Monday, March 25, 2013 1:49 PM

All replies

  • > i need to give full-control read,write for everyone in folder c:\Program Files\MyFolder

    No, you don't. 

    I'm guessing you're falling foul of U.A.C., which is preventing your users from writing to this subdirectory structure. 
    Not wanting to sound adversarial, but Live with it.  UAC is there for a reason - honest.  The more you try to fight against it, the more grief you're going to get.

    I would recommend storing user-updatable data in location(s) that are user-accessible by default.  Zero effort.  If you try and "force" the issue, then it would only take one security Patch to undo all your good work and your application would crash and burn again as, I guess, it's doing now. 

    If you really must have data that is accessible by anyone on the machine, then I would suggest creating another folder (at installation time) somewhere else on the machine (e.g. C:\SharedDataFolder) and give "Users on that machine" (not "Everyone") access to that folder but, for the sake of your sanity, don't try to force it into a known U.A.C. "hotspot". 


    Regards, Phill W.

    Monday, March 25, 2013 12:53 PM
  • Hi,

    you can do this by using DirectorySecurity from namespace System.Security.AccessControl:

    DirectorySecurity ds = Directory.GetAccessControl(@"C:\test");
    ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
    Directory.SetAccessControl(@"C:\test", ds);


    Bilhan silva

    • Marked as answer by E_gold Tuesday, March 26, 2013 7:23 AM
    Monday, March 25, 2013 1:49 PM
  • Hi E_gold,

    Based on your question, I would like to move your thread to Common Language Runtime Internals and Architecture to get more response.

    Thanks for your understanding and support.

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 26, 2013 2:29 AM