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
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
enumServicesStatus(desiredState: number): Promise< Service[] >
Enumerate Windows Services by the desirate state (Default equal to `State.All`). State can be retrieved with the constants **State**.
```ts
export interface ServiceStates {
Active: 0,
Inactive: 1,
All: 2
}
```
The returned value is a Promise that contain an Array of Service.
```ts
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;
};
}
```
enumDependentServices(serviceName: string, desiredState?: number): Promise< DependentServices >
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`.
```ts
export interface DependentServices {
[serviceName: string]: Service;
}
```
> **Warning**: Each Service are a reducted version of the TypeScript interface `Service` (optionals are not in the payload).
getServiceConfiguration(serviceName: string): Promise< ServiceInformation >
Get a given Windows Service configuration. The returned value is a Promise of Object ServiceInformation.
```ts
export interface ServiceInformation {
type: string;
startType: string;
errorControl: string;
binaryPath: string;
account: string;
loadOrderGroup?: string;
tagId?: number;
dependencies?: string;
description?: string;
}
```
getServiceTriggers(serviceName: string): Promise< ServiceTrigger[] >
Get all Service triggers for a given Service name. The returned value is a Promise that contain an Array of ServiceTrigger.
```ts
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
License
MIT