How to give Read/Write permissions to a Folder during installation using .NET

后端 未结 9 1544
不思量自难忘°
不思量自难忘° 2020-11-27 14:33

I have a Setup project that I have build using Visual Studio 2010.

The installer works fine in terms of installing the application and all its dependencies into thei

9条回答
  •  感情败类
    2020-11-27 15:11

    DirectoryInfo info = new DirectoryInfo(path[x]);
    
    DirectorySecurity security = info.GetAccessControl();
    
    security.AddAccessRule(new FileSystemAccessRule(logonName, FileSystemRights.Modify, InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
    
    security.AddAccessRule(new FileSystemAccessRule(logonName, FileSystemRights.Modify, InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
    
    info.SetAccessControl(security); 
    

    Setting the inherit part is also important if you want to save and access more than just one file in the ProgramData folder.

提交回复
热议问题