Skip to content

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));

Functions

exists()

Returns whether the specified operating system service exists.

Signature:

exists( serviceName: string ): boolean

Parameters:

  • serviceName: string

    The 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: string

    The 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: string

    The name of the service to be altered.

  • startupType: startupType

    The 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: string

    The name of the service to be started.

  • waitFor: number, optional

    Maximum number of seconds to wait for the service to be running. 0 or 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: string

    The name of the service to be stopped.

  • waitFor: number, optional

    Maximum number of seconds to wait for the service to stop. 0 or omitted: wait without time limit.

  • force: boolean, optional

    If true and the service has not stopped within waitFor seconds, the process of the service is killed. Default: false.

Return type: boolean

Example:

infinity.loadModule('infinity.service');
if ( infinity.service.stop('MariaDB', 60) ) {
  //...
}

Enums

infinity.service.startupType

Values:

  • autoStart: 2

    Stands for the service starting with the operating system.

  • demandStart: 3

    Stands for the service starting on manual demand.

  • disabled: 4

    Stands for a disabled service.

Example:

infinity.loadModule('infinity.service');
let startupType = infinity.service.startupType.autoStart;

infinity.service.status

Values:

  • unknown: 0

    Stands for a status that can't be determined.

  • stopped: 1

    Stands for a stopped service.

  • startPending: 2

    Stands for a service pending to be started.

  • stopPending: 3

    Stands for a service pending to be shut down.

  • running: 4

    Stands for a running service.

  • continuePending: 5

    Stands for a service pending to be continued.

  • pausePending: 6

    Stands for a service pending to be paused.

  • paused: 7

    Stands for a paused service.

Example:

infinity.loadModule('infinity.service');
let status = infinity.service.status.unknown;