private static SafeServiceHandle OpenService(SafeServiceHandle scManager, string serviceName, int purpose) { SafeServiceHandle handle = ListenerUnsafeNativeMethods.OpenService(scManager, serviceName, purpose); if (handle.IsInvalid) { Exception exception = new Win32Exception(); handle.SetHandleAsInvalid(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception); } return(handle); }
static SafeServiceHandle OpenService(SafeServiceHandle scManager, string serviceName, int purpose) { #pragma warning suppress 56523 // Microsoft, Win32Exception ctor calls Marshal.GetLastWin32Error() SafeServiceHandle service = ListenerUnsafeNativeMethods.OpenService(scManager, serviceName, purpose); if (service.IsInvalid) { Exception exception = new Win32Exception(); service.SetHandleAsInvalid(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception); } return(service); }