GitHunt
JF

jfdesrochers/node-wmi

Library to execute wmi (Windows Management Instrumentation) commands.

node-wmi

Library to execute wmi (Windows Management Instrumentation) commands.

Install

npm install node-wmi

Documentation

Methods

Query([options, callback])

Constructor that generates an instance of the Query class.

Arguments

  • options - Object representing options for the query. Options can also be applied via chain api. (optional)
  • callback(err, result) - Callback. If not supplied query will not be executed until query.exec() method has been called. (optional)

Return Value
The Query method returns an instance of the query class.

Options Properties

  • host (type: string) - Hostname or IP of the client to get information from. Defaults to localhost.
  • namespace (type: string) - Namespace of the class to query. Defaults to root\CIMV2.
  • class (type:string) - Class to be queried for information. (required)
  • properties/props (type: [string])- List of properties of the class to query for. If not set, all properties will be returned for the given class. (optional)
  • username (type: string) - Username to use to perform query. (optional)
  • password (type: string) - Password for the above username. (optional)
  • where (types: string, [string]) - Where clause for the query. The where clause can come in multiple different types. If you pass in a string, it will be accepted as a literal text to go in the where clause. If you pass in an array of strings, they will be And'ed together. (optional)
  • method (type: string) - If specified, the method will be called on the specified class / instance. Unless the method is static, you will also need to include a where clause. If you need to add arguments for the method, please include them in a props statement.

Chainable API
Chainable api methods exists to set each property for the query. To use the chainable api, call the method of the name of the property which you would like to set with the first argument being the value of the property and an optional second argument being a callback function to execute the query.

Callback
The callback has the signature of (err, result). The callback can be supplied as the second argument to either the constructor or any of the chainable functions. The callback is the first and only parameter for the exec method.

Examples

// Object usage

var wmi = require('node-wmi');
wmi.Query({
  class: 'Win32_BIOS'
}, function(err, bios) {
  console.log(bios);
});
// Chainable API reference with exec method

var wmi = require('node-wmi');
wmi.Query().class('Win32_BIOS').exec(function(err, bios) {
  console.log(bios);
});
// Using callback in chainable api

var wmi = require('node-wmi');
wmi.Query().class('Win32_LogicalDisk', function(err, disks) {
  console.log(disks);
});
// Calling methods
var wmi = require('node-wmi');
wmi.Query().class('Win32_Volume').where('DriveLetter="C:"').method('DefragAnalysis', function(err, result) {
  console.log(result)
});
// Calling methods with parameters
var wmi = require('node-wmi');
wmi.Query().class('Win32_Process').method('create').props('C:\\windows\\system32\\notepad.exe', function(err, result) {
  console.log(result)
});

Languages

JavaScript100.0%

Contributors

MIT License
Created January 17, 2019
Updated October 25, 2023