systeminformation 5.10.5 → 5.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -381,9 +381,9 @@ Full function reference with examples can be found at [https://systeminformation
381
381
  | | ...[0].pid | X | X | X | X | X | process PID |
382
382
  | | ...[0].parentPid | X | X | X | X | X | parent process PID |
383
383
  | | ...[0].name | X | X | X | X | X | process name |
384
- | | ...[0].pcpu | X | X | X | X | X | process % CPU usage |
385
- | | ...[0].pcpuu | X | X | | X | | process % CPU usage (user) |
386
- | | ...[0].pcpus | X | X | | X | | process % CPU usage (system) |
384
+ | | ...[0].cpu | X | X | X | X | X | process % CPU usage |
385
+ | | ...[0].cpuu | X | X | | X | | process % CPU usage (user) |
386
+ | | ...[0].cpus | X | X | | X | | process % CPU usage (system) |
387
387
  | | ...[0].pmem | X | X | X | X | X | process memory % |
388
388
  | | ...[0].priority | X | X | X | X | X | process priotity |
389
389
  | | ...[0].memVsz | X | X | X | X | X | process virtual memory size |
package/lib/usb.js CHANGED
@@ -263,7 +263,7 @@ function usb(callback) {
263
263
  });
264
264
  }
265
265
  if (_windows) {
266
- util.powerShell('Get-WmiObject CIM_LogicalDevice | where { $_.Description -match "^USB"}').then((stdout, error) => {
266
+ util.powerShell('Get-WmiObject CIM_LogicalDevice | where { $_.Description -match "USB"}').then((stdout, error) => {
267
267
  if (!error) {
268
268
  const parts = stdout.toString().split(/\n\s*\n/);
269
269
  for (let i = 0; i < parts.length; i++) {
package/lib/users.js CHANGED
@@ -176,44 +176,6 @@ function parseUsersDarwin(lines) {
176
176
  return result;
177
177
  }
178
178
 
179
- // function parseUsersWin(lines, culture) {
180
-
181
- // let result = [];
182
- // const header = lines[0];
183
- // const headerDelimiter = [];
184
- // if (header) {
185
- // const start = (header[0] === ' ') ? 1 : 0;
186
- // headerDelimiter.push(start - 1);
187
- // let nextSpace = 0;
188
- // for (let i = start + 1; i < header.length; i++) {
189
- // if (header[i] === ' ' && ((header[i - 1] === ' ') || (header[i - 1] === '.'))) {
190
- // nextSpace = i;
191
- // } else {
192
- // if (nextSpace) {
193
- // headerDelimiter.push(nextSpace);
194
- // nextSpace = 0;
195
- // }
196
- // }
197
- // }
198
- // for (let i = 1; i < lines.length; i++) {
199
- // if (lines[i].trim()) {
200
- // const user = lines[i].substring(headerDelimiter[0] + 1, headerDelimiter[1]).trim() || '';
201
- // const tty = lines[i].substring(headerDelimiter[1] + 1, headerDelimiter[2] - 2).trim() || '';
202
- // const dateTime = util.parseDateTime(lines[i].substring(headerDelimiter[5] + 1, 2000).trim(), culture) || '';
203
- // result.push({
204
- // user: user,
205
- // tty: tty,
206
- // date: dateTime.date,
207
- // time: dateTime.time,
208
- // ip: '',
209
- // command: ''
210
- // });
211
- // }
212
- // }
213
- // }
214
- // return result;
215
- // }
216
-
217
179
  function users(callback) {
218
180
 
219
181
  return new Promise((resolve) => {
@@ -293,7 +255,8 @@ function users(callback) {
293
255
  // ).then(data => {
294
256
  let cmd = 'Get-WmiObject Win32_LogonSession | fl *' + '; echo \'#-#-#-#\';';
295
257
  cmd += 'Get-WmiObject Win32_LoggedOnUser | fl *' + '; echo \'#-#-#-#\';';
296
- cmd += 'Get-WmiObject Win32_Process -Filter "name=\'explorer.exe\'" | Select @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl';
258
+ cmd += 'Get-WmiObject Win32_Process -Filter "name=\'explorer.exe\'" | Select @{Name="sessionid";Expression={$_.SessionId}}, @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl' + '; echo \'#-#-#-#\';';
259
+ cmd += 'query user';
297
260
  util.powerShell(cmd).then(data => {
298
261
  // controller + vram
299
262
  // let accounts = parseWinAccounts(data[0].split(/\n\s*\n/));
@@ -301,7 +264,8 @@ function users(callback) {
301
264
  data = data.split('#-#-#-#');
302
265
  let sessions = parseWinSessions(data[0].split(/\n\s*\n/));
303
266
  let loggedons = parseWinLoggedOn(data[1].split(/\n\s*\n/));
304
- let users = parseWinUsers(data[2].split(/\n\s*\n/));
267
+ let queryUser = parseWinUsersQuery(data[3].split('\r\n'));
268
+ let users = parseWinUsers(data[2].split(/\n\s*\n/), queryUser);
305
269
  for (let id in loggedons) {
306
270
  if ({}.hasOwnProperty.call(loggedons, id)) {
307
271
  loggedons[id].dateTime = {}.hasOwnProperty.call(sessions, id) ? sessions[id] : '';
@@ -319,7 +283,7 @@ function users(callback) {
319
283
 
320
284
  result.push({
321
285
  user: user.user,
322
- tty: '',
286
+ tty: user.tty,
323
287
  date: `${dateTime.substr(0, 4)}-${dateTime.substr(4, 2)}-${dateTime.substr(6, 2)}`,
324
288
  time: `${dateTime.substr(8, 2)}:${dateTime.substr(10, 2)}`,
325
289
  ip: '',
@@ -380,17 +344,36 @@ function parseWinSessions(sessionParts) {
380
344
  return sessions;
381
345
  }
382
346
 
383
- function parseWinUsers(userParts) {
347
+ function fuzzyMatch(name1, name2) {
348
+ name1 = name1.toLowerCase();
349
+ name2 = name2.toLowerCase();
350
+ let eq = 0;
351
+ let len = name1.length;
352
+ if (name2.length > len) { len = name2.length; }
353
+
354
+ for (let i = 0; i < len; i++) {
355
+ const c1 = name1[i] || '';
356
+ const c2 = name2[i] || '';
357
+ if (c1 === c2) { eq++; }
358
+ }
359
+ return (len > 10 ? eq / len > 0.9 : (len > 0 ? eq / len > 0.8 : false));
360
+ }
361
+
362
+ function parseWinUsers(userParts, userQuery) {
384
363
  const users = [];
385
364
  userParts.forEach(user => {
386
365
  const lines = user.split('\r\n');
387
366
 
388
367
  const domain = util.getValue(lines, 'domain', ':', true);
389
368
  const username = util.getValue(lines, 'username', ':', true);
369
+ const sessionid = util.getValue(lines, 'sessionid', ':', true);
370
+
390
371
  if (username) {
372
+ const quser = userQuery.filter(item => fuzzyMatch(item.user, username));
391
373
  users.push({
392
374
  domain,
393
- user: username
375
+ user: username,
376
+ tty: quser && quser[0] && quser[0].tty ? quser[0].tty : sessionid
394
377
  });
395
378
  }
396
379
  });
@@ -421,4 +404,38 @@ function parseWinLoggedOn(loggedonParts) {
421
404
  return loggedons;
422
405
  }
423
406
 
407
+ function parseWinUsersQuery(lines) {
408
+ lines = lines.filter(item => item);
409
+ let result = [];
410
+ const header = lines[0];
411
+ const headerDelimiter = [];
412
+ if (header) {
413
+ const start = (header[0] === ' ') ? 1 : 0;
414
+ headerDelimiter.push(start - 1);
415
+ let nextSpace = 0;
416
+ for (let i = start + 1; i < header.length; i++) {
417
+ if (header[i] === ' ' && ((header[i - 1] === ' ') || (header[i - 1] === '.'))) {
418
+ nextSpace = i;
419
+ } else {
420
+ if (nextSpace) {
421
+ headerDelimiter.push(nextSpace);
422
+ nextSpace = 0;
423
+ }
424
+ }
425
+ }
426
+ for (let i = 1; i < lines.length; i++) {
427
+ if (lines[i].trim()) {
428
+ const user = lines[i].substring(headerDelimiter[0] + 1, headerDelimiter[1]).trim() || '';
429
+ const tty = lines[i].substring(headerDelimiter[1] + 1, headerDelimiter[2] - 2).trim() || '';
430
+ // const dateTime = util.parseDateTime(lines[i].substring(headerDelimiter[5] + 1, 2000).trim(), culture) || '';
431
+ result.push({
432
+ user: user,
433
+ tty: tty,
434
+ });
435
+ }
436
+ }
437
+ }
438
+ return result;
439
+ }
440
+
424
441
  exports.users = users;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.10.5",
3
+ "version": "5.10.6",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",