infinity.service¶
Provides functionality for checking and controlling operating system services.
Module: infinity.service
Note: This module is only available on Windows. On other platforms,
infinity.loadModule('infinity.service')throws an error (Module infinity.service not found). Controlling services usually requires administrator rights.
Example:
infinity.loadModule('infinity.service');
console.debug(infinity.service.exists('MariaDB'));
console.debug(infinity.service.getStatus('MariaDB'));
console.debug(infinity.service.start('MariaDB', 30));
console.debug(infinity.service.stop('Spooler', 30, true));
console.debug(infinity.service.setStartupType('MariaDB', infinity.service.startupType.autoStart));
exists()¶
Returns whether the specified operating system service exists.
Signature:
exists( serviceName: string ): boolean
Parameters:
- serviceName:
stringThe name of the service to be checked (the service name, not the display name).
Return type: boolean
Example:
infinity.loadModule('infinity.service');
if ( infinity.service.exists('MariaDB') ) {
//...
}
getStatus()¶
Returns the running status of the operating system service according to status. Returns unknown if the service does not exist or its status cannot be queried.
Signature:
getStatus( serviceName: string ): infinity.service.status
Parameters:
- serviceName:
stringThe name of the service to be checked.
Return type: status
Example:
infinity.loadModule('infinity.service');
let status = infinity.service.getStatus('MariaDB');
setStartupType()¶
Attempts to alter the startup type of the specified operating system service. Returns a boolean value indicating success or failure.
Signature:
setStartupType( serviceName: string, startupType: infinity.service.startupType ): boolean
Parameters:
-
serviceName:
stringThe name of the service to be altered.
-
startupType:
startupTypeThe startup type to be set according to
startupType.
Return type: boolean
Example:
infinity.loadModule('infinity.service');
if ( infinity.service.setStartupType('MariaDB', infinity.service.startupType.autoStart) ) {
//...
}
start()¶
Attempts to start the specified operating system service and waits until the service is running or stopped again. Returns true if the service is running afterwards (also if it was already running).
Signature:
start( serviceName: string, waitFor?: number ): boolean
Parameters:
-
serviceName:
stringThe name of the service to be started.
-
waitFor:
number, optionalMaximum number of seconds to wait for the service to be running.
0or omitted: wait without time limit.
Return type: boolean
Example:
infinity.loadModule('infinity.service');
if ( infinity.service.start('MariaDB') ) {
//...
}
stop()¶
Attempts to stop the specified operating system service and waits until the service is stopped. Returns true if the service is stopped afterwards (or, with force, if its process has been killed).
Signature:
stop( serviceName: string, waitFor?: number, force?: boolean ): boolean
Parameters:
-
serviceName:
stringThe name of the service to be stopped.
-
waitFor:
number, optionalMaximum number of seconds to wait for the service to stop.
0or omitted: wait without time limit. -
force:
boolean, optionalIf
trueand the service has not stopped withinwaitForseconds, the process of the service is killed. Default:false.
Return type: boolean
Example:
infinity.loadModule('infinity.service');
if ( infinity.service.stop('MariaDB', 60) ) {
//...
}
infinity.service.startupType¶
Values:
-
autoStart:
2Stands for the service starting with the operating system.
-
demandStart:
3Stands for the service starting on manual demand.
-
disabled:
4Stands for a disabled service.
Example:
infinity.loadModule('infinity.service');
let startupType = infinity.service.startupType.autoStart;
infinity.service.status¶
Values:
-
unknown:
0Stands for a status that can't be determined.
-
stopped:
1Stands for a stopped service.
-
startPending:
2Stands for a service pending to be started.
-
stopPending:
3Stands for a service pending to be shut down.
-
running:
4Stands for a running service.
-
continuePending:
5Stands for a service pending to be continued.
-
pausePending:
6Stands for a service pending to be paused.
-
paused:
7Stands for a paused service.
Example:
infinity.loadModule('infinity.service');
let status = infinity.service.status.unknown;