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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.