@getpid/ms-wmic
v1.1.0
Published
A Node.js wrapper for Microsoft Windows' WMIC
Downloads
86
Maintainers
Readme
node-ms-wmic
A Node.js wrapper for Microsoft Windows' WMIC
Installation
npm i ms-wmic
API
Note: All API methods return the wmic object for chaining.
wmic.execute(args
, cb
)
Execute WMIC with the provided args
- string
args
- WMIC CLI arguments - function(null | object
err
, stringstdOut
)cb
- A function to be called after WMIC is executed
Example
wmic.execute('process where name="notepad.exe" get executablepath', function (err, stdOut) {
if (err) {
console.error(err);
}
console.log(stdOut);
});
wmic.process.get(opt
, cb
)
Retrieve specific process properties given one or more optional search conditions
- object
opt
- An options object- object{string | number} | object{object{string | number}}
where
- (Optional) An object in which a key isoperator
, with a value of "AND" or "OR" (case-insensitive). Will determine how search conditions are joined. If omitted, conditions are joined with "AND".- A process property, with a value of either a process property value to match with an equal to comparison or an object containing
operator
andvalue
keys.operator
is a WQL operator or LIKE Operator.value
is a process property value.
- array{string}
get
- Process properties to get
- object{string | number} | object{object{string | number}}
- function(null | object
err
, array{object{string}}processes
)cb
- A callback to executed after the process properties are retrieved.
Examples
// Get a specific property of all processes
wmic.process.get({get: ['processId']}, function(err, processes, stdOut) {
if (err) {
console.error(err);
}
console.log(processes);
console.log(stdOut);
});
// Simple equal to where comparison
wmic.process.get({
where: {name: 'spotify.exe'},
get: ['name', 'executablePath', 'threadCount']
}, function(err, processes, stdOut) {
if (err) {
console.error(err);
}
console.log(processes);
console.log(stdOut);
});
// Advanced comparison via operators
wmic.process.get({
where: {
operator: 'OR',
writeOperationCount: {
operator: '>',
value: 10
},
executablePath: {
operator: 'LIKE',
value: '%C:\\\\Program Files (x86)%chrome.exe%'
}
},
get: ['workingSetSize', 'processId']
}, function(err, processes, stdOut) {
if (err) {
console.error(err);
}
console.log(processes);
console.log(stdOut);
});
wmic.process.list(where
, cb
)
Retrieve all available process properties given one or more optional search conditions
- object{string | number} | object{object{string | number}}
where
- (Optional) An object in which a key isoperator
, with a value of "AND" or "OR" (case-insensitive). Will determine how search conditions are joined. If omitted, conditions are joined with "AND".- A process property, with a value of either a process property value to match with an equal to comparison or an object containing
operator
andvalue
keys.operator
is a WQL operator or LIKE Operator.value
is a process property value.
- function(null | object
err
, array{object{string}}processes
)cb
- A callback to executed after the process properties are retrieved.
Examples
// Get properties of all processes
wmic.process.list(function(err, processes, stdOut) {
if (err) {
console.error(err);
}
console.log(processes);
console.log(stdOut);
});
// Simple equal to where comparison
wmic.process.list({CSName: 'SOME-MACHINE'}, function(err, processes, stdOut) {
if (err) {
console.error(err);
}
console.log(processes);
console.log(stdOut);
});
// Advanced comparison via operators
wmic.process.list({
operator: 'OR',
threadCount: {
operator: '>',
value: 1
},
name: {
operator: 'LIKE',
value: 'firef[i-p]x.exe'
}
}, function(err, processes, stdOut) {
if (err) {
console.error(err);
}
console.log(processes);
console.log(stdOut);
});
wmic.process.call(opt
, cb
)
Execute a method on process(es) given one or more search conditions
- object
opt
- An options object- object{string | number} | object{object{string | number}}
where
- An object in which a key isoperator
, with a value of "AND" or "OR" (case-insensitive). Will determine how search conditions are joined. If omitted, conditions are joined with "AND".- A process property, with a value of either a process property value to match with an equal to comparison or an object containing
operator
andvalue
keys.operator
is a WQL operator or LIKE Operator.value
is a process property value.
- string
call
- The method to execute
- object{string | number} | object{object{string | number}}
- function(null | object
err
, array{object{string}}stdOut
)cb
- A callback to be executed after the method is called.
Examples
// Simple equal to where comparison
wmic.process.call({
where: { name: 'taskmgr.exe' },
call: 'terminate'
}, function(err, stdOut) {
if (err) {
console.error(err);
}
console.log(stdOut);
});
// Advanced comparison via operators
wmic.process.call({
where: {
operator: 'OR',
name: {
operator: 'LIKE',
value: '%ccleaner%'
}
},
call: 'getowner'
}, function(err, stdOut) {
if (err) {
console.error(err);
}
console.log(stdOut);
});
wmic.process.terminate(opt
, cb
)
Terminate process(es) given one or more search conditions
- object
opt
- An options object- object{string | number} | object{object{string | number}}
where
- An object in which a key isoperator
, with a value of "AND" or "OR" (case-insensitive). Will determine how search conditions are joined. If omitted, conditions are joined with "AND".- A process property, with a value of either a process property value to match with an equal to comparison or an object containing
operator
andvalue
keys.operator
is a WQL operator or LIKE Operator.value
is a process property value.
- object{string | number} | object{object{string | number}}
- function(null | object
err
, array{object{string}}stdOut
)cb
- A callback to be executed after the process(es) are terminated.
Examples
// Simple equal to where comparison
wmic.process.call({
where: { name: 'taskmgr.exe' },
call: 'terminate'
}, function(err, stdOut) {
if (err) {
console.error(err);
}
console.log(stdOut);
});
// Advanced comparison via operators
wmic.process.call({
where: {
operator: 'OR',
name: {
operator: 'LIKE',
value: '%ccleaner%'
}
},
call: 'getowner'
}, function(err, stdOut) {
if (err) {
console.error(err);
}
console.log(stdOut);
});