Java Examples for jnacontrib.jna.WINSVC
The following java examples will help you to understand the usage of jnacontrib.jna.WINSVC. These source code samples are taken from different open source projects.
Example 1
| Project: windows-wrapper-master File: Win32Service.java View source code |
/**
* Install the service.
*
* @return true on success
* @param displayName visible name
* @param description description
* @param dependencies array of other services to depend on or null
* @param account service account or null for LocalSystem
* @param password password for service account or null
* @param command command line to start the service
* @throws java.lang.Exception
*/
public boolean install(String displayName, String description, String[] dependencies, String account, String password, String command) {
Advapi32 advapi32;
Advapi32.SERVICE_DESCRIPTION desc;
Pointer serviceManager, service;
boolean success = false;
String dep = "";
if (dependencies != null) {
for (String s : dependencies) {
dep += s + "\0";
}
}
dep += "\0";
desc = new Advapi32.SERVICE_DESCRIPTION();
desc.lpDescription = description;
advapi32 = Advapi32.INSTANCE;
serviceManager = openServiceControlManager(null, WINSVC.SC_MANAGER_ALL_ACCESS);
if (serviceManager != null) {
service = advapi32.CreateService(serviceManager, serviceName, displayName, WINSVC.SERVICE_ALL_ACCESS, WINSVC.SERVICE_WIN32_OWN_PROCESS, WINSVC.SERVICE_DEMAND_START, WINSVC.SERVICE_ERROR_NORMAL, command, null, null, dep, account, password);
if (service != null) {
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_DESCRIPTION, desc);
advapi32.CloseServiceHandle(service);
}
advapi32.CloseServiceHandle(serviceManager);
}
return (success);
}Example 2
| Project: yajsw-maven-master File: Win32Service.java View source code |
/**
* Install the service.
*
* @return true on success
* @param displayName
* visible name
* @param description
* description
* @param dependencies
* array of other services to depend on or null
* @param account
* service account or null for LocalSystem
* @param password
* password for service account or null
* @param command
* command line to start the service
* @throws java.lang.Exception
*/
public boolean install(String displayName, String description, String[] dependencies, String account, String password, String command, String startType, boolean interactive, Object failureActions) {
Advapi32 advapi32;
Advapi32.SERVICE_DESCRIPTION desc;
Pointer serviceManager, service;
boolean success = false;
String dep = "";
if (dependencies != null) {
for (String s : dependencies) {
dep += s + "\0";
}
}
dep += "\0";
desc = new Advapi32.SERVICE_DESCRIPTION();
desc.lpDescription = description;
advapi32 = Advapi32.INSTANCE;
serviceManager = openServiceControlManager(null, WINSVC.SC_MANAGER_ALL_ACCESS);
int winStartType = "DEMAND_START".equals(startType) ? WINSVC.SERVICE_DEMAND_START : WINSVC.SERVICE_AUTO_START;
int dwServiceType = WINSVC.SERVICE_WIN32_OWN_PROCESS;
if (interactive)
dwServiceType |= WINSVC.SERVICE_INTERACTIVE_PROCESS;
if (serviceManager != null) {
service = advapi32.CreateService(serviceManager, serviceName, displayName, WINSVC.SERVICE_ALL_ACCESS, dwServiceType, winStartType, WINSVC.SERVICE_ERROR_NORMAL, command, null, null, dep, account, password);
if (service != null) {
if (failureActions != null) {
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_FAILURE_ACTIONS, (SERVICE_FAILURE_ACTIONS) failureActions);
if (!success) {
int err = Native.getLastError();
System.out.println("ERROR Setting failure actions #" + err + " " + Kernel32Util.formatMessageFromLastErrorCode(err));
}
}
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_DESCRIPTION, desc);
if (Platform.isWinVista() && "DELAYED_AUTO_START".equals(startType)) {
Advapi32.SERVICE_DELAYED_AUTO_START_INFO delayedDesc = new Advapi32.SERVICE_DELAYED_AUTO_START_INFO();
delayedDesc.fDelayedAutostart = true;
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_DELAYED_AUTO_START_INFO, delayedDesc);
}
advapi32.CloseServiceHandle(service);
} else {
int err = Kernel32.INSTANCE.GetLastError();
System.out.println("error during install " + err);
System.out.println(Kernel32Util.formatMessageFromLastErrorCode(err));
}
advapi32.CloseServiceHandle(serviceManager);
}
return (success);
}Example 3
| Project: yajsw-maven-mk2-master File: Win32Service.java View source code |
/**
* Install the service.
*
* @return true on success
* @param displayName
* visible name
* @param description
* description
* @param dependencies
* array of other services to depend on or null
* @param account
* service account or null for LocalSystem
* @param password
* password for service account or null
* @param command
* command line to start the service
* @throws java.lang.Exception
*/
public boolean install(String displayName, String description, String[] dependencies, String account, String password, String command, String startType, boolean interactive, Object failureActions) {
Advapi32 advapi32;
Advapi32.SERVICE_DESCRIPTION desc;
Pointer serviceManager, service;
boolean success = false;
String dep = "";
if (dependencies != null) {
for (String s : dependencies) {
dep += s + "\0";
}
}
dep += "\0";
desc = new Advapi32.SERVICE_DESCRIPTION();
desc.lpDescription = description;
advapi32 = Advapi32.INSTANCE;
serviceManager = openServiceControlManager(null, WINSVC.SC_MANAGER_ALL_ACCESS);
int winStartType = "DEMAND_START".equals(startType) ? WINSVC.SERVICE_DEMAND_START : WINSVC.SERVICE_AUTO_START;
int dwServiceType = WINSVC.SERVICE_WIN32_OWN_PROCESS;
if (interactive)
dwServiceType |= WINSVC.SERVICE_INTERACTIVE_PROCESS;
if (serviceManager != null) {
service = advapi32.CreateService(serviceManager, serviceName, displayName, WINSVC.SERVICE_ALL_ACCESS, dwServiceType, winStartType, WINSVC.SERVICE_ERROR_NORMAL, command, null, null, dep, account, password);
if (service != null) {
if (failureActions != null) {
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_FAILURE_ACTIONS, (SERVICE_FAILURE_ACTIONS) failureActions);
if (!success) {
int err = Native.getLastError();
System.out.println("ERROR Setting failure actions #" + err + " " + Kernel32Util.formatMessageFromLastErrorCode(err));
}
}
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_DESCRIPTION, desc);
if (Platform.isWinVista() && "DELAYED_AUTO_START".equals(startType)) {
Advapi32.SERVICE_DELAYED_AUTO_START_INFO delayedDesc = new Advapi32.SERVICE_DELAYED_AUTO_START_INFO();
delayedDesc.fDelayedAutostart = true;
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_DELAYED_AUTO_START_INFO, delayedDesc);
}
advapi32.CloseServiceHandle(service);
} else {
int err = Kernel32.INSTANCE.GetLastError();
System.out.println("error during install " + err);
System.out.println(Kernel32Util.formatMessageFromLastErrorCode(err));
}
advapi32.CloseServiceHandle(serviceManager);
}
return (success);
}Example 4
| Project: yajsw-master File: Win32Service.java View source code |
/**
* Install the service.
*
* @return true on success
* @param displayName
* visible name
* @param description
* description
* @param dependencies
* array of other services to depend on or null
* @param account
* service account or null for LocalSystem
* @param password
* password for service account or null
* @param command
* command line to start the service
* @throws java.lang.Exception
*/
public boolean install(String displayName, String description, String[] dependencies, String account, String password, String command, String startType, boolean interactive) {
Advapi32 advapi32;
Advapi32.SERVICE_DESCRIPTION desc;
Pointer serviceManager, service;
boolean success = false;
String dep = "";
if (dependencies != null) {
for (String s : dependencies) {
dep += s + "\0";
}
}
dep += "\0";
desc = new Advapi32.SERVICE_DESCRIPTION();
desc.lpDescription = description;
advapi32 = Advapi32.INSTANCE;
serviceManager = openServiceControlManager(null, WINSVC.SC_MANAGER_ALL_ACCESS);
int winStartType = "DEMAND_START".equals(startType) ? WINSVC.SERVICE_DEMAND_START : WINSVC.SERVICE_AUTO_START;
int dwServiceType = WINSVC.SERVICE_WIN32_OWN_PROCESS;
if (interactive)
dwServiceType |= WINSVC.SERVICE_INTERACTIVE_PROCESS;
if (serviceManager != null) {
service = advapi32.CreateService(serviceManager, serviceName, displayName, WINSVC.SERVICE_ALL_ACCESS, dwServiceType, winStartType, WINSVC.SERVICE_ERROR_NORMAL, command, null, null, dep, account, password);
if (service != null) {
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_DESCRIPTION, desc);
advapi32.CloseServiceHandle(service);
} else {
int err = Kernel32.INSTANCE.GetLastError();
System.out.println("error during install " + err);
System.out.println(Kernel32Util.formatMessageFromLastErrorCode(err));
}
advapi32.CloseServiceHandle(serviceManager);
}
return (success);
}