Search in sources :

Example 1 with SERVICE_STATUS

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);
}
Also used : SERVICE_STATUS(com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS)

Example 2 with SERVICE_STATUS

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);
}
Also used : SC_HANDLE(com.sun.jna.platform.win32.Winsvc.SC_HANDLE) SERVICE_STATUS(com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS)

Aggregations

SERVICE_STATUS (com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS)2 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)1