Top Description Fields Constructors Methods
com.sun.jna.platform.win32

public Class W32Service

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.util.List, com.sun.jna.Memory, .Pointer, .Structure, com.sun.jna.platform.win32.WinDef.DWORD, .WinNT.HANDLEByReference, .WinNT.LUID, .WinNT.LUID_AND_ATTRIBUTES, .WinNT.TOKEN_PRIVILEGES, .Winsvc.ENUM_SERVICE_STATUS, .Winsvc.SC_ACTION, .Winsvc.SC_HANDLE, .Winsvc.SC_STATUS_TYPE, .Winsvc.SERVICE_FAILURE_ACTIONS, .Winsvc.SERVICE_FAILURE_ACTIONS_FLAG, .Winsvc.SERVICE_STATUS, .Winsvc.SERVICE_STATUS_PROCESS, com.sun.jna.ptr.IntByReference, java.io.Closeable

Win32 Service wrapper
Author
EugineLev

Field Summary

Modifier and TypeField and Description
pack-priv Winsvc.SC_HANDLE

Constructor Summary

AccessConstructor and Description
public
W32Service(Winsvc.SC_HANDLE
A handle to the service. This handle is returned by the CreateService or OpenService function, and it must have the SERVICE_QUERY_STATUS access right.
handle
)

Win32 Service

Method Summary

Modifier and TypeMethod and Description
private void
public void
close()

Implements java.io.Closeable.close.

Close service.
public void
continueService()

Continue service.

public Winsvc.ENUM_SERVICE_STATUS[]

Returns:

array of ENUM_SERVICE_STATUS structures that receives the name and service status information for each dependent service in the database.
enumDependentServices
(int
The state of the services to be enumerated. This parameter can be one of the following values.
ValueMeaning
Winsvc#SERVICE_ACTIVEEnumerates services that are in the following states: Winsvc#SERVICE_START_PENDING, Winsvc#SERVICE_STOP_PENDING, Winsvc#SERVICE_RUNNING, Winsvc#SERVICE_CONTINUE_PENDING, Winsvc#SERVICE_PAUSE_PENDING, and Winsvc#SERVICE_PAUSED.
Winsvc#SERVICE_INACTIVEEnumerates services that are in the Winsvc#SERVICE_STOPPED state.
Winsvc#SERVICE_STATE_ALLCombines the following states: Winsvc#SERVICE_ACTIVE and Winsvc#SERVICE_INACTIVE.
dwServiceState
)

Retrieves the name and status of each service that depends on the specified service; that is, the specified service must be running before the dependent services can run.

public Winsvc.SERVICE_FAILURE_ACTIONS
getFailureActions()

Get the failure actions of the specified service.

public boolean
getFailureActionsFlag()

Get the failure actions flag of the specified service.

public Winsvc.SC_HANDLE

Returns:

Returns the service handle.
getHandle
()

Gets the service handle.

private boolean
isPendingState(int state)

public void
pauseService()

Pause service.

private Pointer
public Winsvc.SERVICE_STATUS_PROCESS

Returns:

Service status information
queryStatus
()

Retrieves the current status of the specified service based on the specified information level.

pack-priv int
sanitizeWaitTime(int dwWaitHint)

do not wait longer than the wait hint.

public void
setFailureActions(List<Winsvc.SC_ACTION> actions, int resetPeriod, String rebootMsg, String command)

Set the failure actions of the specified service.

public void
setFailureActionsFlag(boolean flagValue)

Set the failure action flag of the specified service.

public void
public void
stopService()

Stop service.

public void
stopService(long
timeout in ms until the service must report to be stopped
timeout
)

Stop service.

public void
waitForNonPendingState()

Wait for the state to change to something other than a pending state.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_handleback to summary
pack-priv Winsvc.SC_HANDLE _handle

Constructor Detail

W32Serviceback to summary
public W32Service(Winsvc.SC_HANDLE handle)

Win32 Service

Parameters
handle:Winsvc.SC_HANDLE

A handle to the service. This handle is returned by the CreateService or OpenService function, and it must have the SERVICE_QUERY_STATUS access right.

Method Detail

addShutdownPrivilegeToProcessback to summary
private void addShutdownPrivilegeToProcess()
closeback to summary
public void close()

Implements java.io.Closeable.close.

Close service.

Annotations
@Override
continueServiceback to summary
public void continueService()

Continue service.

enumDependentServicesback to summary
public Winsvc.ENUM_SERVICE_STATUS[] enumDependentServices(int dwServiceState)

Retrieves the name and status of each service that depends on the specified service; that is, the specified service must be running before the dependent services can run.

Parameters
dwServiceState:int

The state of the services to be enumerated. This parameter can be one of the following values.

ValueMeaning
Winsvc#SERVICE_ACTIVEEnumerates services that are in the following states: Winsvc#SERVICE_START_PENDING, Winsvc#SERVICE_STOP_PENDING, Winsvc#SERVICE_RUNNING, Winsvc#SERVICE_CONTINUE_PENDING, Winsvc#SERVICE_PAUSE_PENDING, and Winsvc#SERVICE_PAUSED.
Winsvc#SERVICE_INACTIVEEnumerates services that are in the Winsvc#SERVICE_STOPPED state.
Winsvc#SERVICE_STATE_ALLCombines the following states: Winsvc#SERVICE_ACTIVE and Winsvc#SERVICE_INACTIVE.
Returns:Winsvc.ENUM_SERVICE_STATUS[]

array of ENUM_SERVICE_STATUS structures that receives the name and service status information for each dependent service in the database.

getFailureActionsback to summary
public Winsvc.SERVICE_FAILURE_ACTIONS getFailureActions()

Get the failure actions of the specified service. Corresponds to QueryServiceConfig2 with parameter dwInfoLevel set to SERVICE_CONFIG_FAILURE_ACTIONS.

getFailureActionsFlagback to summary
public boolean getFailureActionsFlag()

Get the failure actions flag of the specified service. Corresponds to QueryServiceConfig2 with parameter dwInfoLevel set to SERVICE_CONFIG_FAILURE_ACTIONS_FLAG.

getHandleback to summary
public Winsvc.SC_HANDLE getHandle()

Gets the service handle.

Returns:Winsvc.SC_HANDLE

Returns the service handle.

isPendingStateback to summary
private boolean isPendingState(int state)
pauseServiceback to summary
public void pauseService()

Pause service.

queryServiceConfig2back to summary
private Pointer queryServiceConfig2(int type)
queryStatusback to summary
public Winsvc.SERVICE_STATUS_PROCESS queryStatus()

Retrieves the current status of the specified service based on the specified information level.

Returns:Winsvc.SERVICE_STATUS_PROCESS

Service status information

sanitizeWaitTimeback to summary
pack-priv int sanitizeWaitTime(int dwWaitHint)

do not wait longer than the wait hint. A good interval is one-tenth the wait hint, but no less than 1 second and no more than 10 seconds.

setFailureActionsback to summary
public void setFailureActions(List<Winsvc.SC_ACTION> actions, int resetPeriod, String rebootMsg, String command)

Set the failure actions of the specified service. Corresponds to ChangeServiceConfig2 with parameter dwInfoLevel set to SERVICE_CONFIG_FAILURE_ACTIONS.

setFailureActionsFlagback to summary
public void setFailureActionsFlag(boolean flagValue)

Set the failure action flag of the specified service. Corresponds to ChangeServiceConfig2 with parameter dwInfoLevel set to SERVICE_CONFIG_FAILURE_ACTIONS_FLAG.

startServiceback to summary
public void startService()
stopServiceback to summary
public void stopService()

Stop service.

stopServiceback to summary
public void stopService(long timeout)

Stop service.

Parameters
timeout:long

timeout in ms until the service must report to be stopped

waitForNonPendingStateback to summary
public void waitForNonPendingState()

Wait for the state to change to something other than a pending state.