public class Service extends Handle
Note: Available for Windows NT, Windows 2000, Windows XP, Windows Server 2003.
Modifier and Type | Class and Description |
---|---|
static class |
Service.AccessRights
This class represents access rights to a service.
|
static class |
Service.CurrentState
This class represents the current state of the service.
|
static class |
Service.ErrorControl |
static class |
Service.StartupType
This class represents startup type of service.
|
static class |
Service.Status
This class represents the service status.
|
static interface |
Service.StatusListener |
static class |
Service.Type
This class represents type of the service.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACCOUNT_LOCAL_SYSTEM |
INFINITE_TIMEOUT, INVALID_HANDLE_VALUE, STATUS_ABANDONED_WAIT_0, STATUS_TIMEOUT, STATUS_WAIT_0
Modifier | Constructor and Description |
---|---|
protected |
Service(java.lang.String name)
Creates a service in open state.
|
protected |
Service(java.lang.String name,
Service.AccessRights accessRights)
Creates a service in open state.
|
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.
|
RegistryKey |
createParametersKey()
Creates parameters subkey in registry.
|
void |
delete()
Marks the service as deleted.
|
Service.AccessRights |
getAccessRights()
Returns access rights for the service.
|
java.lang.String |
getBinaryPath()
Returns the absolute path to the executable file for the service.
|
Service.CurrentState |
getCurrentState()
Returns the current state of the service.
|
java.lang.String[] |
getDependencies()
Returns names of the services that the system must start before starting this service.
|
java.lang.String |
getDescription()
Returns description for the service.
|
java.lang.String |
getDisplayName()
Returns the display name of the service.
|
Service.ErrorControl |
getErrorControl()
Returns severity of the error that describes the action performed if the service failed to start:
Error codes ErrorControl.IGNORE Logs error and continues startup ErrorControl.NORMAL Logs error, shows message box with error message and continues startup ErrorControl.SEVERE Logs error. |
java.lang.String |
getName()
Returns the service name used for openning the service.
|
java.lang.String |
getPassword() |
Service.Type |
getServiceType()
Returns a type of the service.
|
java.lang.String |
getStartAccount()
Returns the account under which the service starts in the form:
domainName\\userName or LocalSystem for
LocalSystem account. |
Service.StartupType |
getStartupType()
Returns startup type of the service.
|
Service.Status |
getStatus()
Returns the service status.
|
boolean |
isInteractive()
Returns true, if the service can interact with desktop.
|
protected boolean |
isLocked() |
protected boolean |
isOpened() |
void |
loadConfiguration()
Loads the configuration of the service.
|
protected void |
lock()
Locks the handle for closing.
|
void |
pause()
Pauses the service.
|
void |
resume()
Resumes the paused service.
|
void |
saveConfiguration()
Saves configuration of the service.
|
void |
setAccessRights(Service.AccessRights accessRights)
Sets access rights to the service.
|
void |
setBinaryPath(java.lang.String binaryPath)
Sets the absolute path to the executable file for the service.
|
void |
setDependencies(java.lang.String[] dependencies)
Sets dependencies for the service.
|
void |
setDisplayName(java.lang.String displayName)
Sets the display name.
|
void |
setErrorControl(Service.ErrorControl errorControl)
Sets severity of the error that describes the action performed if the service failed to start:
ErrorControl.IGNORE Logs error and continues startup ErrorControl.NORMAL Logs error, shows message box with error message and continues startup ErrorControl.SEVERE Logs error. |
void |
setInteractive(boolean isInteractive)
Allows / disallows interaction of the service with desktop.
|
void |
setName(java.lang.String name)
Sets service name.
|
protected void |
setOpened(boolean isOpened) |
void |
setPassword(java.lang.String password)
Sets password for the start account.
|
void |
setServiceType(Service.Type serviceType)
Sets a type of the service.
|
void |
setStartAccount(java.lang.String startAccount)
Sets the account under which the service starts.
|
void |
setStartupType(Service.StartupType startupType)
Sets startup type of the service.
|
void |
setValue(long value)
Sets handle value of this pointer to service.
|
void |
start()
Starts the service.
|
void |
start(java.lang.String[] parameters)
Starts the service.
|
void |
stop()
Stops the service.
|
protected void |
unlock()
Unlocks the handle for closing.
|
void |
waitState(Service.CurrentState expectedState)
Periodically checks the current state of the service and returns from the method
when the current state is equal to the expected state.
|
void |
waitState(Service.CurrentState[] expectedStates)
Periodically checks the current state of the service and returns from the method
when the current state is equal to one of the expected states.
|
void |
waitState(Service.CurrentState[] expectedStates,
Service.StatusListener listener)
Periodically checks the current state of the service and returns from the method
when the current state is equal to one of the expected states.
|
void |
waitState(Service.CurrentState expectedState,
Service.StatusListener listener)
Periodically checks the current state of the service and returns from the method
when the current state is equal to the expected state.
|
clone, closeHandle, equals, waitFor, waitFor
asFunction, asFunction, asTypedPointer, castTo, castTo, getDebugInfo, getLength, getValue, hashCode, isNull, read, toString, write
public static final java.lang.String ACCOUNT_LOCAL_SYSTEM
protected Service(java.lang.String name, Service.AccessRights accessRights)
name
- service name used for opening.accessRights
- access rights to service.protected Service(java.lang.String name)
name
- service name used for openingpublic void setValue(long value)
setValue
in interface com.jniwrapper.IntegerParameter
setValue
in class com.jniwrapper.Pointer.Void
public java.lang.String getName()
public void setName(java.lang.String name)
name
- service name.public java.lang.String getDisplayName()
public void setDisplayName(java.lang.String displayName)
saveConfiguration()
method must be called to apply the changes.displayName
- display name.public Service.Type getServiceType()
public void setServiceType(Service.Type serviceType)
saveConfiguration()
method must be called to apply the changes.serviceType
- service type.public boolean isInteractive()
public void setInteractive(boolean isInteractive)
saveConfiguration()
method must be called to apply the changes.isInteractive
- if true, the service can interact with desktop; otherwise the service can't interact with desktop.public Service.ErrorControl getErrorControl()
ErrorControl.IGNORE | Logs error and continues startup |
ErrorControl.NORMAL | Logs error, shows message box with error message and continues startup |
ErrorControl.SEVERE | Logs error. If the last-known good configuration is started then continues startup else system is restarted with last-known good configuration |
ErrorControl.CRITICAL | Logs error if possible. If the last-known good configuration is started then startup is failed else system is restarted with last-known good configuration |
public void setErrorControl(Service.ErrorControl errorControl)
ErrorControl.IGNORE | Logs error and continues startup |
ErrorControl.NORMAL | Logs error, shows message box with error message and continues startup |
ErrorControl.SEVERE | Logs error. If the last-known good configuration is started then continues startup else system is restarted with last-known good configuration |
ErrorControl.CRITICAL | Logs error if possible. If the last-known good configuration is started then startup is failed else system is restarted with last-known good configuration |
The saveConfiguration()
method must be called to apply the changes.
errorControl
- severity of the error.public Service.StartupType getStartupType()
public void setStartupType(Service.StartupType startupType)
saveConfiguration()
method must be called to apply the changes.startupType
- new startup type.public java.lang.String getBinaryPath()
Note: The path is quoted when the path contains spaces. For example: "c:\Program files\myservice.exe".
public void setBinaryPath(java.lang.String binaryPath)
Note: If the path contains spaces, it must be quoted (for example, "c:\Program files\myservice.exe").
binaryPath
- the absolute path to the executable file for the service.public Service.AccessRights getAccessRights()
public void setAccessRights(Service.AccessRights accessRights)
saveConfiguration()
method must be called to apply the changes.accessRights
- new access rights.public java.lang.String[] getDependencies()
public void setDependencies(java.lang.String[] dependencies)
saveConfiguration()
method must be called to apply the changes.dependencies
- names of services that the system must start before this service.public java.lang.String getStartAccount()
domainName\\userName
or LocalSystem
for
LocalSystem
account.public void setStartAccount(java.lang.String startAccount)
saveConfiguration()
method must be called to apply the changes.startAccount
- start account for service in the form:
domainName\\userName
or LocalSystem
for
LocalSystem
account.public java.lang.String getPassword()
public void setPassword(java.lang.String password)
saveConfiguration()
method must be called to apply the changes.password
- account password.public void start()
Note: The service start can be still in progress after the method returns.
You can use waitState(Service.CurrentState)
after invoking this method for waiting until the service
finishes the start up sequence.
public void start(java.lang.String[] parameters)
parameters
- startup parameters.public void stop()
Note: The service stopping can be in progress after the method returns.
You can use waitState(Service.CurrentState)
after calling this method for waiting until the service is stopped.
public void pause()
public void resume()
public Service.Status getStatus()
public Service.CurrentState getCurrentState()
public void loadConfiguration()
public java.lang.String getDescription()
""
when running under Windows NT.public void saveConfiguration()
loadConfiguration()
prior to invoking set of getters to update the configuration.public void delete()
public void waitState(Service.CurrentState expectedState) throws java.lang.InterruptedException
expectedState
- expected statesjava.lang.InterruptedException
public void waitState(Service.CurrentState expectedState, Service.StatusListener listener) throws java.lang.InterruptedException
expectedState
- expected stateslistener
- listener that notified when is acquired current state of servicejava.lang.InterruptedException
public void waitState(Service.CurrentState[] expectedStates) throws java.lang.InterruptedException
expectedStates
- expected statesjava.lang.InterruptedException
public void waitState(Service.CurrentState[] expectedStates, Service.StatusListener listener) throws java.lang.InterruptedException
expectedStates
- expected stateslistener
- listener that notified when is acquired current state of servicejava.lang.InterruptedException
public RegistryKey createParametersKey()
RegistryKey parametersKey = service.createParametersKey();
parametersKey.values().put("logfile", "D:/tomcat/logs/error.error");
parametersKey.close();
Location of created subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\service_name
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
.