C#如何给文件夹添加本地服务权限
How to add local service priviledge on folder by C#
我正在寻找如何通过 C# 以编程方式在 C:\Program Files
中的文件夹上添加本地服务权限,并从这个 url 中获得了一篇文章
他们展示了如何为 everyone
用户执行此操作。
DirectorySecurity sec = Directory.GetAccessControl(path);
// Using this instead of the "Everyone" string means we work on non-English systems.
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(path, sec);
请告诉我我需要在上面的代码中更改什么,因此 local service
权限将添加到特定文件夹。
我开发了一个 windows 服务,它将在 运行 时在其中创建一个文件夹和 xml 文件。当我从安装文件安装我的服务时,文件夹没有被创建,但也没有错误 return.
所以我调试了该服务,发现它可以在调试期间在其中创建文件夹和 xml 文件。当我从安装文件安装服务时出现问题。我无法捕获问题,例如发生了什么问题。因此,请指导我如何解决问题,例如 "Why my service not being able to create folder and file " 寻求指导。谢谢
new SecurityIdentifier(WellKnownSidType.LocalServiceSid, null);
或
new SecurityIdentifier("S-1-5-19");
我正在寻找如何通过 C# 以编程方式在 他们展示了如何为 请告诉我我需要在上面的代码中更改什么,因此 我开发了一个 windows 服务,它将在 运行 时在其中创建一个文件夹和 xml 文件。当我从安装文件安装我的服务时,文件夹没有被创建,但也没有错误 return. 所以我调试了该服务,发现它可以在调试期间在其中创建文件夹和 xml 文件。当我从安装文件安装服务时出现问题。我无法捕获问题,例如发生了什么问题。因此,请指导我如何解决问题,例如 "Why my service not being able to create folder and file " 寻求指导。谢谢C:\Program Files
中的文件夹上添加本地服务权限,并从这个 url 中获得了一篇文章
everyone
用户执行此操作。DirectorySecurity sec = Directory.GetAccessControl(path);
// Using this instead of the "Everyone" string means we work on non-English systems.
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(path, sec);
local service
权限将添加到特定文件夹。
new SecurityIdentifier(WellKnownSidType.LocalServiceSid, null);
或
new SecurityIdentifier("S-1-5-19");