I have C# Windows service class:
class MyService : ServiceBase
{
private void InitializeComponent() {
//some other code ...
SafeHandle sHandle = this.ServiceHandle; // I want to do this but this fails.
SetServiceObjectSecurity(sHandle, secInfo, binaryDescriptor);
//some more code ...
}
}
How to convert an IntPtr (like this.ServiceHandle) to a "System.Runtime.InteropServices.SafeHandle"? so that I can use that in the function call "SetServiceObjectSecurity()"? My ultimate aim is to give admin permission to the Service.