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; }
if (! Advapi32.INSTANCE.ControlService(_handle, SERVICE_CONTROL_STOP, status)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
/** * 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"); } }
/** * 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"); } }
/** * 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"); } }