windows-service-manager

A node module to query, stop (optionally forcefully) and start Windows services

A node module to query, start and stop Windows services. Uses the sc and taskkill programs which is present on every version of Windows since Windows XP.

The functions return service objects containing the following fields:

  • name: the service name
  • description: the optional service description, may not be present
  • state: an integer state code with the following possible values
    • 1: STOPPED
    • 2: STOP PENDING
    • 3: START PENDING
    • 4: STARTED
    • 5: CONTINUE PENDING
    • 6: PAUSE PENDING
    • 7: PAUSED
  • stateDescription: the textual description of the state as shown above
  • pid: the process identifier for the service, if it is running

queryServices asynchronously returns an array of service objects, for all services installed on the system.

Parameters:

  • callback: a callback function function(error, service):
    • error: error that occured or null if no error
    • service: an array of service objects for all installed services.

Example:

var serviceManager = require('./windows-service-manager');

serviceManager.queryServices(function(error, services) {
    console.log(error || services);
});

queryService asynchronously returns an service object for the service with the specified name.

Parameters:

  • name: the name of the service to query.
  • callback: a callback function function(error, service):
    • error: error that occured or null if no error
    • service: a service object for the service named name.

Example:

var serviceManager = require('./windows-service-manager');

serviceManager.queryServices(function(error, services) {
    console.log(error || services);
});

startService asynchronously starts a service with the specified name. If the service is already started