@slimio/winservices
v1.3.0
Published
Windows Services - Node.JS low level binding
Downloads
8
Readme
Winservices
SlimIO Windows Services is a Node.js Binding which expose low-level Microsoft APIs to fetch Services state, configuration and triggers.
The binding expose the following methods/struct:
Requirements
- Node.js v12 or higher
Getting Started
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @slimio/winservices
# or
$ yarn add @slimio/winservices
Usage example
Get all active windows services and retrieve advanced informations for each of them in series.
const services = require("@slimio/winservices");
const { States } = services.constants;
async function main() {
const activeServices = await services.enumServicesStatus(States.Active);
for (const service of activeServices) {
console.log(`service name: ${service.name}`);
const serviceConfig = await services.getServiceConfiguration(service.name);
console.log(JSON.stringify(serviceConfig, null, 4));
console.log("------------------------------\n");
}
}
main().catch(console.error);
API
Enumerate Windows Services by the desirate state (Default equal to State.All
). State can be retrieved with the constants State.
export interface ServiceStates {
Active: 0,
Inactive: 1,
All: 2
}
The returned value is a Promise that contain an Array of Service.
export interface Service {
name: string,
displayName: string;
process: {
id?: number;
name?: string;
currentState: number;
serviceType: number;
checkPoint?: number;
controlsAccepted: number;
serviceFlags?: number;
serviceSpecificExitCode: number;
waitHint: number;
win32ExitCode: number;
};
}
Enumerate dependent Windows Services of a given Service name. The returned value is a Promise of Object DependentServices.
Default value for desiredState is State.All
.
export interface DependentServices {
[serviceName: string]: Service;
}
Warning: Each Service are a reducted version of the TypeScript interface
Service
(optionals are not in the payload).
Get a given Windows Service configuration. The returned value is a Promise of Object ServiceInformation.
export interface ServiceInformation {
type: string;
startType: string;
errorControl: string;
binaryPath: string;
account: string;
loadOrderGroup?: string;
tagId?: number;
dependencies?: string;
description?: string;
}
Get all Service triggers for a given Service name. The returned value is a Promise that contain an Array of ServiceTrigger.
export interface ServiceTrigger {
type: number;
action: number;
guid: string;
dataItems: ServiceTriggerSpecificDataItem[]
}
export interface ServiceTriggerSpecificDataItem {
dataType: number;
data?: string;
}
Contribution Guidelines
To contribute to the project, please read the code of conduct and the guide for N-API compilation.
Dependencies
|Name|Refactoring|Security Risk|Usage| |---|---|---|---| |node-addon-api|⚠️Major|Low|Node.js C++ addon api| |node-gyp-build|⚠️Major|Low|Node-gyp builder|
License
MIT