use of com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS in project jna by java-native-access.
the class Win32Service method reportStatus.
/**
* Report service status to the ServiceControlManager.
*
* @param status status
* @param win32ExitCode exit code
* @param waitHint time to wait
*/
private void reportStatus(int status, int win32ExitCode, int waitHint) {
Advapi32 advapi32;
SERVICE_STATUS serviceStatus;
advapi32 = Advapi32.INSTANCE;
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;
advapi32.SetServiceStatus(serviceStatusHandle, serviceStatus);
}
use of com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS in project jna by java-native-access.
the class Win32Service method stop.
/**
* Ask the ServiceControlManager to stop the service.
* @return true on success
*/
public boolean stop() throws Exception {
Advapi32 advapi32;
SC_HANDLE serviceManager, service;
SERVICE_STATUS serviceStatus;
boolean success = false;
advapi32 = Advapi32.INSTANCE;
serviceManager = openServiceControlManager(null, WinNT.GENERIC_EXECUTE);
if (serviceManager != null) {
service = advapi32.OpenService(serviceManager, serviceName, WinNT.GENERIC_EXECUTE);
if (service != null) {
serviceStatus = new SERVICE_STATUS();
success = advapi32.ControlService(service, Winsvc.SERVICE_CONTROL_STOP, serviceStatus);
advapi32.CloseServiceHandle(service);
}
advapi32.CloseServiceHandle(serviceManager);
}
return (success);
}
Aggregations