return; SERVICE_STATUS status = new SERVICE_STATUS(); if (! Advapi32.INSTANCE.ControlService(_handle, SERVICE_CONTROL_STOP, status)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
/** * Stop service. */ public void stopService() { waitForNonPendingState(); // If the service is already stopped - return if (queryStatus().dwCurrentState == Winsvc.SERVICE_STOPPED) { return; } if (! Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_STOP, new Winsvc.SERVICE_STATUS())) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } waitForNonPendingState(); if (queryStatus().dwCurrentState != Winsvc.SERVICE_STOPPED) { throw new RuntimeException("Unable to stop the service"); } }
/** * Continue service. */ public void continueService() { waitForNonPendingState(); // If the service is already stopped - return if (queryStatus().dwCurrentState == Winsvc.SERVICE_RUNNING) { return; } if (! Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_CONTINUE, new Winsvc.SERVICE_STATUS())) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } waitForNonPendingState(); if (queryStatus().dwCurrentState != Winsvc.SERVICE_RUNNING) { throw new RuntimeException("Unable to continue the service"); } }
/** * Pause service. */ public void pauseService() { waitForNonPendingState(); // If the service is already paused - return if (queryStatus().dwCurrentState == Winsvc.SERVICE_PAUSED) { return; } if (! Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_PAUSE, new Winsvc.SERVICE_STATUS())) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } waitForNonPendingState(); if (queryStatus().dwCurrentState != Winsvc.SERVICE_PAUSED) { throw new RuntimeException("Unable to pause the service"); } }
/** * Continue service. */ public void continueService() { waitForNonPendingState(); // If the service is already stopped - return if (queryStatus().dwCurrentState == Winsvc.SERVICE_RUNNING) { return; } if (! Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_CONTINUE, new Winsvc.SERVICE_STATUS())) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } waitForNonPendingState(); if (queryStatus().dwCurrentState != Winsvc.SERVICE_RUNNING) { throw new RuntimeException("Unable to continue the service"); } }
/** * Pause service. */ public void pauseService() { waitForNonPendingState(); // If the service is already paused - return if (queryStatus().dwCurrentState == Winsvc.SERVICE_PAUSED) { return; } if (! Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_PAUSE, new Winsvc.SERVICE_STATUS())) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } waitForNonPendingState(); if (queryStatus().dwCurrentState != Winsvc.SERVICE_PAUSED) { throw new RuntimeException("Unable to pause the service"); } }
public boolean stop() { boolean success = false; SC_HANDLE serviceManager = openServiceControlManager(null, WinNT.GENERIC_EXECUTE); if (serviceManager != null) { SC_HANDLE service = Advapi32.INSTANCE.OpenService(serviceManager, serviceName, WinNT.GENERIC_EXECUTE); if (service != null) { SERVICE_STATUS serviceStatus = new SERVICE_STATUS(); success = Advapi32.INSTANCE.ControlService(service, Winsvc.SERVICE_CONTROL_STOP, serviceStatus); Advapi32.INSTANCE.CloseServiceHandle(service); } Advapi32.INSTANCE.CloseServiceHandle(serviceManager); } return success; }
private void reportStatus(int status, int win32ExitCode, int waitHint) { SERVICE_STATUS serviceStatus = new SERVICE_STATUS(); serviceStatus.dwServiceType = WinNT.SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwControlsAccepted = Winsvc.SERVICE_ACCEPT_STOP | Winsvc.SERVICE_ACCEPT_SHUTDOWN; serviceStatus.dwWin32ExitCode = win32ExitCode; serviceStatus.dwWaitHint = waitHint; serviceStatus.dwCurrentState = status; ADVAPI_32.SetServiceStatus(serviceStatusHandle, serviceStatus); }