public new void Stop() { using (WinServiceNative native = new WinServiceNative()) { native.Lock(); native.Open(this.ServiceName); ApiStructs.ServiceStatus ss = native.QueryStatus(); if (ss.CurrentState != ApiEnums.ServiceState.SERVICE_RUNNING) { throw new Win32Exception("Cannot start the service because it is not running"); } } }
public ApiStructs.ServiceStatus QueryStatus() { if (!this.IsOpen) { throw new Win32Exception("Service not yet open."); } ApiStructs.ServiceStatus status = new ApiStructs.ServiceStatus(); int bytesNeeded = 0; if (!ApiAdvapi32.QueryServiceStatusEx(m_service, 0, ref status, Marshal.SizeOf(status), ref bytesNeeded)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "Unable to query service status."); } return(status); }