Skip to content

Commit 551f09c

Browse files
committed
Initial commit. Closes mjhasbach/MS-Task#1
0 parents  commit 551f09c

File tree

5 files changed

+524
-0
lines changed

5 files changed

+524
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
node_modules/

LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 Matthew Hasbach
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# node-ms-wmic
2+
3+
node-ms-wmic is a Node.js wrapper for Microsoft Windows' [WMIC](https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx).
4+
5+
## Installation
6+
```
7+
npm i ms-wmic
8+
```
9+
10+
## API
11+
12+
Note: All API methods return the wmic object for chaining.
13+
14+
#### wmic.execute(```args```, ```cb```)
15+
16+
Execute WMIC with the provided `args`
17+
18+
* string `args` - WMIC CLI arguments
19+
* function(null | object `err`, string `stdOut`) `cb` - A function to be called after WMIC is executed
20+
21+
__Example__
22+
23+
```
24+
wmic.query('process where name="notepad.exe" get executablepath', function (err, stdOut) {
25+
if (err) {
26+
console.error(err);
27+
}
28+
29+
console.log(stdOut);
30+
});
31+
```
32+
33+
#### wmic.process.get(```opt```, ```cb```)
34+
35+
Retrieve specific process properties given one or more optional search conditions
36+
37+
* object `opt` - An options object
38+
* object{string | number} | object{object{string | number}} `where` - (Optional) An object in which a key is
39+
1. `operator`, with a value of "AND" or "OR" (case-insensitive). Will determine how search conditions are joined.
40+
2. A process property, with a value of either a process property value to match with an equal to comparison or an object containing `operator` and `value` keys. `operator` is a [WQL operator](https://msdn.microsoft.com/en-us/library/aa394605(v=vs.85).aspx) or [LIKE Operator](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). `value` is a process property value.
41+
* array{string} `get` - Process properties to get
42+
* function(null | object `err`, array{object{string}} `processes`) `cb` - A callback to executed after the process properties are retrieved.
43+
44+
__Examples__
45+
46+
```
47+
// Get a specific property of all processes
48+
wmic.process.get({get: ['processId']}, function(err, processes, stdOut) {
49+
if (err) {
50+
console.error(err);
51+
}
52+
53+
console.log(processes);
54+
console.log(stdOut);
55+
});
56+
57+
// Simple equal to where comparison
58+
wmic.process.get({
59+
where: {name: 'spotify.exe'},
60+
get: ['name', 'executablePath', 'threadCount']
61+
}, function(err, processes, stdOut) {
62+
if (err) {
63+
console.error(err);
64+
}
65+
66+
console.log(processes);
67+
console.log(stdOut);
68+
});
69+
70+
// Advanced comparison via operators
71+
wmic.process.get({
72+
where: {
73+
operator: 'OR',
74+
writeOperationCount: {
75+
operator: '>',
76+
value: 10
77+
},
78+
executablePath: {
79+
operator: 'LIKE',
80+
value: '%C:\\\\Program Files (x86)%chrome.exe%'
81+
}
82+
},
83+
get: ['workingSetSize', 'processId']
84+
}, function(err, processes, stdOut) {
85+
if (err) {
86+
console.error(err);
87+
}
88+
89+
console.log(processes);
90+
console.log(stdOut);
91+
});
92+
```
93+
94+
#### wmic.process.list(```where```, ```cb```)
95+
96+
Retrieve all available process properties given one or more optional search conditions
97+
98+
* object{string | number} | object{object{string | number}} `where` - (Optional) An object in which a key is
99+
1. `operator`, with a value of "AND" or "OR" (case-insensitive). Will determine how search conditions are joined.
100+
2. A process property, with a value of either a process property value to match with an equal to comparison or an object containing `operator` and `value` keys. `operator` is a [WQL operator](https://msdn.microsoft.com/en-us/library/aa394605(v=vs.85).aspx) or [LIKE Operator](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). `value` is a process property value.
101+
* function(null | object `err`, array{object{string}} `processes`) `cb` - A callback to executed after the process properties are retrieved.
102+
103+
__Examples__
104+
105+
```
106+
// Get properties of all processes
107+
wmic.process.list(function(err, processes, stdOut) {
108+
if (err) {
109+
console.error(err);
110+
}
111+
112+
console.log(processes);
113+
console.log(stdOut);
114+
});
115+
116+
// Simple equal to where comparison
117+
wmic.process.list({CSName: 'SOME-MACHINE'}, function(err, processes, stdOut) {
118+
if (err) {
119+
console.error(err);
120+
}
121+
122+
console.log(processes);
123+
console.log(stdOut);
124+
});
125+
126+
// Advanced comparison via operators
127+
wmic.process.list({
128+
operator: 'OR',
129+
threadCount: {
130+
operator: '>',
131+
value: 1
132+
},
133+
name: {
134+
operator: 'LIKE',
135+
value: 'firef[i-p]x.exe'
136+
}
137+
}, function(err, processes, stdOut) {
138+
if (err) {
139+
console.error(err);
140+
}
141+
142+
console.log(processes);
143+
console.log(stdOut);
144+
});
145+
```
146+
147+
#### wmic.process.call(```opt```, ```cb```)
148+
149+
Execute a method on process(es) given one or more search conditions
150+
151+
* object `opt` - An options object
152+
* object{string | number} | object{object{string | number}} `where` - An object in which a key is
153+
1. `operator`, with a value of "AND" or "OR" (case-insensitive). Will determine how search conditions are joined.
154+
2. A process property, with a value of either a process property value to match with an equal to comparison or an object containing `operator` and `value` keys. `operator` is a [WQL operator](https://msdn.microsoft.com/en-us/library/aa394605(v=vs.85).aspx) or [LIKE Operator](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). `value` is a process property value.
155+
* string `call` - The method to execute
156+
* function(null | object `err`, array{object{string}} `stdOut`) `cb` - A callback to be executed after the method is called.
157+
158+
__Examples__
159+
160+
```
161+
// Simple equal to where comparison
162+
wmic.process.call({
163+
where: { name: 'taskmgr.exe' },
164+
call: 'terminate'
165+
}, function(err, stdOut) {
166+
if (err) {
167+
console.error(err);
168+
}
169+
170+
console.log(stdOut);
171+
});
172+
173+
// Advanced comparison via operators
174+
wmic.process.call({
175+
where: {
176+
operator: 'OR',
177+
name: {
178+
operator: 'LIKE',
179+
value: '%ccleaner%'
180+
}
181+
},
182+
call: 'getowner'
183+
}, function(err, stdOut) {
184+
if (err) {
185+
console.error(err);
186+
}
187+
188+
console.log(stdOut);
189+
});
190+
```
191+
192+
#### wmic.process.terminate(```opt```, ```cb```)
193+
194+
Terminate process(es) given one or more search conditions
195+
196+
* object `opt` - An options object
197+
* object{string | number} | object{object{string | number}} `where` - An object in which a key is
198+
1. `operator`, with a value of "AND" or "OR" (case-insensitive). Will determine how search conditions are joined.
199+
2. A process property, with a value of either a process property value to match with an equal to comparison or an object containing `operator` and `value` keys. `operator` is a [WQL operator](https://msdn.microsoft.com/en-us/library/aa394605(v=vs.85).aspx) or [LIKE Operator](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). `value` is a process property value.
200+
* function(null | object `err`, array{object{string}} `stdOut`) `cb` - A callback to be executed after the process(es) are terminated.
201+
202+
__Examples__
203+
204+
```
205+
// Simple equal to where comparison
206+
wmic.process.call({
207+
where: { name: 'taskmgr.exe' },
208+
call: 'terminate'
209+
}, function(err, stdOut) {
210+
if (err) {
211+
console.error(err);
212+
}
213+
214+
console.log(stdOut);
215+
});
216+
217+
// Advanced comparison via operators
218+
wmic.process.call({
219+
where: {
220+
operator: 'OR',
221+
name: {
222+
operator: 'LIKE',
223+
value: '%ccleaner%'
224+
}
225+
},
226+
call: 'getowner'
227+
}, function(err, stdOut) {
228+
if (err) {
229+
console.error(err);
230+
}
231+
232+
console.log(stdOut);
233+
});
234+
```

0 commit comments

Comments
 (0)