systeminformation 5.10.2 → 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/battery.js CHANGED
@@ -244,13 +244,13 @@ module.exports = function (callback) {
244
244
  batteries[batteries.length - 1].push(parts[i]);
245
245
  }
246
246
  }
247
- let designCapacities = data.results[1].split('\r\n');
248
- let fullChargeCapacities = data.results[2].split('\r\n');
247
+ let designCapacities = data.results[1].split('\r\n').filter(e => e);
248
+ let fullChargeCapacities = data.results[2].split('\r\n').filter(e => e);
249
249
  if (batteries.length) {
250
250
  let first = false;
251
251
  let additionalBatteries = [];
252
252
  for (let i = 0; i < batteries.length; i++) {
253
- let lines = batteries[i];
253
+ let lines = batteries[i][0].split('\r\n');
254
254
  const designedCapacity = designCapacities && designCapacities.length >= (i + 1) && designCapacities[i] ? util.toInt(designCapacities[i]) : 0;
255
255
  const fullChargeCapacity = fullChargeCapacities && fullChargeCapacities.length >= (i + 1) && fullChargeCapacities[i] ? util.toInt(fullChargeCapacities[i]) : 0;
256
256
  const parsed = parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity);
package/lib/processes.js CHANGED
@@ -324,13 +324,13 @@ function services(srv, callback) {
324
324
  }
325
325
  if (_windows) {
326
326
  try {
327
- let wincommand = "Get-WmiObject Win32_Service";
327
+ let wincommand = 'Get-WmiObject Win32_Service';
328
328
  if (srvs[0] !== '*') {
329
329
  wincommand += ' -Filter "';
330
330
  for (let i = 0; i < srvs.length; i++) {
331
331
  wincommand += `Name='${srvs[i]}' or `;
332
332
  }
333
- wincommand = `${wincommand.slice(0,-4)}"`;
333
+ wincommand = `${wincommand.slice(0, -4)}"`;
334
334
  }
335
335
  wincommand += ' | fl *';
336
336
  util.powerShell(wincommand).then((stdout, error) => {
@@ -817,8 +817,8 @@ function processes(callback) {
817
817
  let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
818
818
  let stime = parseInt(util.getValue(lines, 'KernelModeTime', ':', true), 10);
819
819
  let memw = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
820
- allcpuu = allcpuu + utime;
821
- allcpus = allcpus + stime;
820
+ allcpuu += utime - (_processes_cpu.list[pid] ? _processes_cpu.list[pid].utime : 0);
821
+ allcpus += stime - (_processes_cpu.list[pid] ? _processes_cpu.list[pid].stime : 0);
822
822
  result.all++;
823
823
  if (!statusValue) { result.unknown++; }
824
824
  if (statusValue === '3') { result.running++; }
@@ -982,8 +982,8 @@ function processLoad(proc, callback) {
982
982
  let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
983
983
  let stime = parseInt(util.getValue(lines, 'KernelModeTime', ':', true), 10);
984
984
  let mem = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
985
- allcpuu = allcpuu + utime;
986
- allcpus = allcpus + stime;
985
+ allcpuu += utime - (_process_cpu.list[pid] ? _process_cpu.list[pid].utime : 0);
986
+ allcpus += stime - (_process_cpu.list[pid] ? _process_cpu.list[pid].stime : 0);
987
987
 
988
988
  procStats.push({
989
989
  pid: pid,
package/lib/system.js CHANGED
@@ -353,33 +353,21 @@ function system(callback) {
353
353
  result.serial = util.getValue(lines, 'identifyingnumber', ':');
354
354
  result.uuid = util.getValue(lines, 'uuid', ':').toLowerCase();
355
355
  // detect virtual (1)
356
- if (result.model.toLowerCase() === 'virtualbox' || result.model.toLowerCase() === 'kvm' || result.model.toLowerCase() === 'virtual machine' || result.model.toLowerCase() === 'bochs' || result.model.toLowerCase().startsWith('vmware')) {
356
+ const model = result.model.toLowerCase();
357
+ if (model === 'virtualbox' || model === 'kvm' || model === 'virtual machine' || model === 'bochs' || model.startsWith('vmware') || model.startsWith('qemu')) {
357
358
  result.virtual = true;
358
- switch (result.model.toLowerCase()) {
359
- case 'virtualbox':
360
- result.virtualHost = 'VirtualBox';
361
- break;
362
- case 'vmware':
363
- result.virtualHost = 'VMware';
364
- break;
365
- case 'kvm':
366
- result.virtualHost = 'KVM';
367
- break;
368
- case 'bochs':
369
- result.virtualHost = 'bochs';
370
- break;
371
- }
359
+ if (model.startsWith('virtualbox')) { result.virtualHost = 'VirtualBox'; }
360
+ if (model.startsWith('vmware')) { result.virtualHost = 'VMware'; }
361
+ if (model.startsWith('kvm')) { result.virtualHost = 'KVM'; }
362
+ if (model.startsWith('bochs')) { result.virtualHost = 'bochs'; }
363
+ if (model.startsWith('qemu')) { result.virtualHost = 'KVM'; }
372
364
  }
373
- if (result.manufacturer.toLowerCase().startsWith('vmware') || result.manufacturer.toLowerCase() === 'xen') {
365
+ const manufacturer = result.manufacturer.toLowerCase();
366
+ if (manufacturer.startsWith('vmware') || manufacturer.startsWith('qemu') || manufacturer === 'xen') {
374
367
  result.virtual = true;
375
- switch (result.manufacturer.toLowerCase()) {
376
- case 'vmware':
377
- result.virtualHost = 'VMware';
378
- break;
379
- case 'xen':
380
- result.virtualHost = 'Xen';
381
- break;
382
- }
368
+ if (manufacturer.startsWith('vmware')) { result.virtualHost = 'VMware'; }
369
+ if (manufacturer.startsWith('xen')) { result.virtualHost = 'Xen'; }
370
+ if (manufacturer.startsWith('qemu')) { result.virtualHost = 'KVM'; }
383
371
  }
384
372
  util.powerShell('Get-WmiObject MS_Systeminformation -Namespace "root/wmi" | fl *').then((stdout, error) => {
385
373
  if (!error) {
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.2",
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)",