Пример #1
0
  /**
   * Uninstall the service.
   *
   * @throws java.lang.Exception
   * @return true on success
   */
  public boolean uninstall() {
    Advapi32 advapi32;
    SC_HANDLE serviceManager, service;
    boolean success = false;

    advapi32 = Advapi32.INSTANCE;
    serviceManager = openServiceControlManager(null, Winsvc.SC_MANAGER_ALL_ACCESS);

    if (serviceManager != null) {
      service = advapi32.OpenService(serviceManager, serviceName, Winsvc.SERVICE_ALL_ACCESS);

      if (service != null) {
        success = advapi32.DeleteService(service);
        advapi32.CloseServiceHandle(service);
      }
      advapi32.CloseServiceHandle(serviceManager);
    }
    return (success);
  }
Пример #2
0
  /**
   * Ask the ServiceControlManager to start the service.
   *
   * @return true on success
   */
  public boolean start() {
    Advapi32 advapi32;
    SC_HANDLE serviceManager, service;
    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) {
        success = advapi32.StartService(service, 0, null);
        advapi32.CloseServiceHandle(service);
      }
      advapi32.CloseServiceHandle(serviceManager);
    }

    return (success);
  }
Пример #3
0
  /**
   * 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);
  }