public class ServiceManager extends Handle
Note: Service objects obtained from this class must be closed when done.
Service service = serviceManager.open("myservice");
// last usage of service object
service.start();
service.close();
Note: Available for Windows NT, Windows 2000, Windows XP, Windows Server 2003.
Modifier and Type | Class and Description |
---|---|
static class |
ServiceManager.AccessRights
This class represents access to the service manager.
|
INFINITE_TIMEOUT, INVALID_HANDLE_VALUE, STATUS_ABANDONED_WAIT_0, STATUS_TIMEOUT, STATUS_WAIT_0
Constructor and Description |
---|
ServiceManager()
Creates a service manager with full access.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkOpened() |
protected void |
checkResult(java.lang.String msg,
com.jniwrapper.Bool result)
A utility method for checking an operation result.
|
boolean |
close()
Closes the handle to a service-related object.
|
Service |
create(java.lang.String serviceName,
java.lang.String displayName,
java.io.File executable)
Creates a service with given attributes in the service database.
|
Service |
create(java.lang.String serviceName,
java.lang.String displayName,
java.io.File executable,
Service.StartupType startupType)
Creates a service with given attributes in the service database.
|
Service |
create(java.lang.String serviceName,
java.lang.String displayName,
java.io.File executable,
Service.StartupType startupType,
java.lang.String[] dependencies)
Creates a service with given attributes in the service database.
|
Service |
create(java.lang.String serviceName,
java.lang.String displayName,
java.io.File executableFile,
Service.StartupType startupType,
java.lang.String[] dependencies,
Service.AccessRights access,
Service.Type serviceType,
Service.ErrorControl errorControl,
java.lang.String startAccount,
java.lang.String password)
Creates a service with the given attributes in the service database.
|
ServiceManager.AccessRights |
getAccess()
Returns access to the service manager.
|
java.lang.String |
getComputerName()
Returns the name of the computer to where create, enumerate or open services.
|
java.lang.String[] |
getServiceNames()
Returns names of all registered services.
|
Service[] |
getServices()
Returns available services.
|
Service[] |
getServices(Service.AccessRights serviceAccessRight)
Returns available services.
|
protected boolean |
isLocked() |
protected boolean |
isOpened() |
protected void |
lock()
Locks the handle for closing.
|
Service |
open(java.lang.String serviceName)
Opens an existing service.
|
Service |
open(java.lang.String serviceName,
Service.AccessRights access)
Opens an existing service.
|
void |
setAccess(ServiceManager.AccessRights access)
Sets access to the service manager.
|
void |
setComputerName(java.lang.String computerName)
Sets the name of the computer to where create, enumerate or open services.
|
protected void |
setOpened(boolean isOpened) |
protected void |
unlock()
Unlocks the handle for closing.
|
clone, closeHandle, equals, waitFor, waitFor
asFunction, asFunction, asTypedPointer, castTo, castTo, getDebugInfo, getLength, getValue, hashCode, isNull, read, setValue, toString, write
public ServiceManager()
public java.lang.String getComputerName()
public void setComputerName(java.lang.String computerName)
public ServiceManager.AccessRights getAccess()
public void setAccess(ServiceManager.AccessRights access)
To access services on remote computer use query status access right shown in the sample below:
ServiceManager.AccessRights accessRights = new ServiceManager.AccessRights();
accessRights.setEnumerateService(true);
serviceManager.setAccess(accessRights);
access
- access to the service manager.public Service create(java.lang.String serviceName, java.lang.String displayName, java.io.File executable)
computerName
property is set.serviceName
- service name.displayName
- display name.executable
- binary path of the executable file for the service.java.lang.RuntimeException
- if fails to create a service.public Service create(java.lang.String serviceName, java.lang.String displayName, java.io.File executable, Service.StartupType startupType)
computerName
property is set.serviceName
- service name.displayName
- display name.executable
- binary path of the executable file for the service.startupType
- startup type of service.java.lang.RuntimeException
- if fails to create a service.public Service create(java.lang.String serviceName, java.lang.String displayName, java.io.File executable, Service.StartupType startupType, java.lang.String[] dependencies)
computerName
property is set.serviceName
- service name.displayName
- display name.executable
- binary path of the executable file for the service.startupType
- startup type of the service.dependencies
- names of services that the system must start before this service.java.lang.RuntimeException
- if fails to create a service.public Service create(java.lang.String serviceName, java.lang.String displayName, java.io.File executableFile, Service.StartupType startupType, java.lang.String[] dependencies, Service.AccessRights access, Service.Type serviceType, Service.ErrorControl errorControl, java.lang.String startAccount, java.lang.String password)
computerName
property is set.serviceName
- service name.displayName
- display name.executableFile
- executable file for the service.startupType
- startup type of the service.dependencies
- names of services that the system must start before this service.access
- access to the service.serviceType
- service type.errorControl
- error control for the service.startAccount
- Account under which the service starts:
in the form domainName\\userName or null for LocalSystem account.password
- password for start account.java.lang.RuntimeException
- if fails to create service.public Service open(java.lang.String serviceName)
serviceName
- service name.java.lang.RuntimeException
- if the service is not found.public Service open(java.lang.String serviceName, Service.AccessRights access)
serviceName
- service name.access
- access to the service.java.lang.RuntimeException
- if the service is not found.public Service[] getServices()
Use getServices(Service.AccessRights) method for getting services on remote computer.
Note: Returned services are in open state.
So you should call service.close()
for each returned service.
public Service[] getServices(Service.AccessRights serviceAccessRight)
To access services on remote computer use query status access right shown in the sample below:
Service.AccessRights serviceAccessRights = new Service.AccessRights();
serviceAccessRights.setQueryStatus(true);
Service[] remoteServices = serviceManager.getServices(serviceAccessRights);
Note: Returned services are in open state.
So you should call service.close()
for each returned service.
serviceAccessRight
- access rights for opened servicespublic java.lang.String[] getServiceNames()
protected void setOpened(boolean isOpened)
protected boolean isOpened()
protected void lock()
protected void unlock()
protected boolean isLocked()
true
, if the handle is locked for closing.protected void checkOpened() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the handle is closed.public boolean close()
protected void checkResult(java.lang.String msg, com.jniwrapper.Bool result)
msg
- error message for the exception to be thrown.result
- boolean value to verify.ServiceException
- if the result is false
.