Reputation: 1093
I want to set permission to a service for certain user via C# code on a Windows server as shown below:
The .NET classes like ServiceController etc. don't have any methods/properties to do this.
How can I do this?
Upvotes: 2
Views: 2640
Reputation: 6049
You are going to need to use PInvoke from c# to call to the Win32 libraries to be able to set permissions for a Windows service. It is a bit complicated if you have never done it before, but here is a good example of setting up a Windows service and its associated permissions:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb540474%28v=vs.85%29.aspx
If you know C++, it might be a better idea to use that language, and put the Windows service code in a .dll that you call from C#. The example above will give you a good start and you should be able to customize what you need to do from there.
Upvotes: 1