开发者

Programmatically assigned network service access to folder using c#

开发者 https://www.devze.com 2023-02-25 08:06 出处:网络
I have an installer that runs some c# code. I want the c# code to give \'full control\' to a folder for the \'network service\' account. Is this possible?

I have an installer that runs some c# code. I want the c# code to give 'full control' to a folder for the 'network service' account. Is this possible?

I see some examples online with connecting to a domain. But the network servic开发者_开发百科e is not on a domain it's a local account and I just wanted to know how to do it in c#?

Cheers


DirectoryInfo dirInfo = new DirectoryInfo("C:\\TestDir2");
DirectorySecurity dirSecurity = dirInfo.GetAccessControl();

dirSecurity.AddAccessRule(new FileSystemAccessRule("ASPNET", FileSystemRights.Write|FileSystemRights.DeleteSubdirectoriesAndFiles, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));

dirInfo.SetAccessControl(dirSecurity);

Mentioned at: Setting access rights for a directory - receiving exception "No flags can be set"
A more generic sample can be found at: http://www.redmondpie.com/applying-permissions-on-any-windows-folder-using-c/

0

精彩评论

暂无评论...
验证码 换一张
取 消