我有 C# Windows 服务类:
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 ...
}
}
如何将 IntPtr(如 this.ServiceHandle)转换为“System.Runtime.InteropServices.SafeHandle”?以便我可以在函数调用“SetServiceObjectSecurity()”中使用它?我的最终目标是授予该服务的管理员权限。