public unsafe void Stop() { if (!this.controlGranted) { new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, this.machineName, this.ServiceName).Demand(); this.controlGranted = true; } IntPtr serviceHandle = this.GetServiceHandle(0x20); try { for (int i = 0; i < this.DependentServices.Length; i++) { ServiceController controller = this.DependentServices[i]; controller.Refresh(); if (controller.Status != ServiceControllerStatus.Stopped) { controller.Stop(); controller.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30)); } } System.ServiceProcess.NativeMethods.SERVICE_STATUS pStatus = new System.ServiceProcess.NativeMethods.SERVICE_STATUS(); if (!System.ServiceProcess.UnsafeNativeMethods.ControlService(serviceHandle, 1, &pStatus)) { Exception innerException = CreateSafeWin32Exception(); throw new InvalidOperationException(Res.GetString("StopService", new object[] { this.ServiceName, this.MachineName }), innerException); } } finally { SafeNativeMethods.CloseServiceHandle(serviceHandle); } }
private unsafe void GenerateStatus() { if (!this.statusGenerated) { if (!this.browseGranted) { new ServiceControllerPermission(ServiceControllerPermissionAccess.Browse, this.machineName, this.ServiceName).Demand(); this.browseGranted = true; } IntPtr serviceHandle = this.GetServiceHandle(4); try { System.ServiceProcess.NativeMethods.SERVICE_STATUS pStatus = new System.ServiceProcess.NativeMethods.SERVICE_STATUS(); if (!System.ServiceProcess.UnsafeNativeMethods.QueryServiceStatus(serviceHandle, &pStatus)) { throw CreateSafeWin32Exception(); } this.commandsAccepted = pStatus.controlsAccepted; this.status = (ServiceControllerStatus)pStatus.currentState; this.type = pStatus.serviceType; this.statusGenerated = true; } finally { SafeNativeMethods.CloseServiceHandle(serviceHandle); } } }
public unsafe void Pause() { if (!this.controlGranted) { new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, this.machineName, this.ServiceName).Demand(); this.controlGranted = true; } IntPtr serviceHandle = this.GetServiceHandle(0x40); try { System.ServiceProcess.NativeMethods.SERVICE_STATUS pStatus = new System.ServiceProcess.NativeMethods.SERVICE_STATUS(); if (!System.ServiceProcess.UnsafeNativeMethods.ControlService(serviceHandle, 2, &pStatus)) { Exception innerException = CreateSafeWin32Exception(); throw new InvalidOperationException(Res.GetString("PauseService", new object[] { this.ServiceName, this.MachineName }), innerException); } } finally { SafeNativeMethods.CloseServiceHandle(serviceHandle); } }
public unsafe void Stop() { if (!this.controlGranted) { new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, this.machineName, this.ServiceName).Demand(); this.controlGranted = true; } IntPtr serviceHandle = this.GetServiceHandle(0x20); try { for (int i = 0; i < this.DependentServices.Length; i++) { ServiceController controller = this.DependentServices[i]; controller.Refresh(); if (controller.Status != ServiceControllerStatus.Stopped) { controller.Stop(); controller.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30)); } } System.ServiceProcess.NativeMethods.SERVICE_STATUS pStatus = new System.ServiceProcess.NativeMethods.SERVICE_STATUS(); if (!System.ServiceProcess.UnsafeNativeMethods.ControlService(serviceHandle, 1, &pStatus)) { Exception innerException = CreateSafeWin32Exception(); throw new InvalidOperationException(Res.GetString("StopService", new object[] { this.ServiceName, this.MachineName }), innerException); } } finally { SafeNativeMethods.CloseServiceHandle(serviceHandle); } }
public unsafe void Pause() { if (!this.controlGranted) { new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, this.machineName, this.ServiceName).Demand(); this.controlGranted = true; } IntPtr serviceHandle = this.GetServiceHandle(0x40); try { System.ServiceProcess.NativeMethods.SERVICE_STATUS pStatus = new System.ServiceProcess.NativeMethods.SERVICE_STATUS(); if (!System.ServiceProcess.UnsafeNativeMethods.ControlService(serviceHandle, 2, &pStatus)) { Exception innerException = CreateSafeWin32Exception(); throw new InvalidOperationException(Res.GetString("PauseService", new object[] { this.ServiceName, this.MachineName }), innerException); } } finally { SafeNativeMethods.CloseServiceHandle(serviceHandle); } }
private unsafe void GenerateStatus() { if (!this.statusGenerated) { if (!this.browseGranted) { new ServiceControllerPermission(ServiceControllerPermissionAccess.Browse, this.machineName, this.ServiceName).Demand(); this.browseGranted = true; } IntPtr serviceHandle = this.GetServiceHandle(4); try { System.ServiceProcess.NativeMethods.SERVICE_STATUS pStatus = new System.ServiceProcess.NativeMethods.SERVICE_STATUS(); if (!System.ServiceProcess.UnsafeNativeMethods.QueryServiceStatus(serviceHandle, &pStatus)) { throw CreateSafeWin32Exception(); } this.commandsAccepted = pStatus.controlsAccepted; this.status = (ServiceControllerStatus) pStatus.currentState; this.type = pStatus.serviceType; this.statusGenerated = true; } finally { SafeNativeMethods.CloseServiceHandle(serviceHandle); } } }