Mou
Mou

Reputation: 16272

How to add local service priviledge on folder by C#

i was finding how to programmatically add local service priviledge on folder in C:\Program Files by C# and got a write up from this url http://stackoverflow.com/questions/5298905/add-everyone-privilege-to-folder-using-c-net/5398398#5398398

they show how to do this for everyone user.

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);

just tell me what i need to change in above code as a result local service privilege will be add on a specific folder.

i develop a windows service which will create a folder and xml file in it at run time. when i install my service from setup file then folder is not getting created but no error is also return.

so i debug the service and saw it could create folder and xml file in it during debugging time. the issue is occurred when i install the service from setup file. i am not being able to capture the issue like what problem is occuring. so guide me what should i do to capture the issue like "Why my service not being able to create folder and file " looking for guidance. thanks

Upvotes: 0

Views: 425

Answers (1)

soumasandesu
soumasandesu

Reputation: 311

new SecurityIdentifier(WellKnownSidType.LocalServiceSid, null);

or

new SecurityIdentifier("S-1-5-19");

Upvotes: 3

Related Questions