systeminformation 5.10.3 → 5.10.7

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,10 +381,10 @@ 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) |
387
- | | ...[0].pmem | X | X | X | X | X | process memory % |
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
+ | | ...[0].mem | 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 |
390
390
  | | ...[0].memRss | X | X | X | X | X | process mem resident set 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) => {
@@ -803,8 +803,10 @@ function processes(callback) {
803
803
  let procs = [];
804
804
  let procStats = [];
805
805
  let list_new = {};
806
- let allcpuu = _processes_cpu.all_utime;
807
- let allcpus = _processes_cpu.all_stime;
806
+ let allcpuu = 0;
807
+ let allcpus = 0;
808
+ // let allcpuu = _processes_cpu.all_utime;
809
+ // let allcpus = _processes_cpu.all_stime;
808
810
  for (let i = 0; i < processSections.length; i++) {
809
811
  if (processSections[i].trim() !== '') {
810
812
  let lines = processSections[i].trim().split('\r\n');
@@ -819,6 +821,8 @@ function processes(callback) {
819
821
  let memw = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
820
822
  allcpuu = allcpuu + utime;
821
823
  allcpus = allcpus + stime;
824
+ // allcpuu += utime - (_processes_cpu.list[pid] ? _processes_cpu.list[pid].utime : 0);
825
+ // allcpus += stime - (_processes_cpu.list[pid] ? _processes_cpu.list[pid].stime : 0);
822
826
  result.all++;
823
827
  if (!statusValue) { result.unknown++; }
824
828
  if (statusValue === '3') { result.running++; }
@@ -970,8 +974,10 @@ function processLoad(proc, callback) {
970
974
  let processSections = stdout.split(/\n\s*\n/);
971
975
  let procStats = [];
972
976
  let list_new = {};
973
- let allcpuu = _process_cpu.all_utime;
974
- let allcpus = _process_cpu.all_stime;
977
+ let allcpuu = 0;
978
+ let allcpus = 0;
979
+ // let allcpuu = _process_cpu.all_utime;
980
+ // let allcpus = _process_cpu.all_stime;
975
981
 
976
982
  // go through all processes
977
983
  for (let i = 0; i < processSections.length; i++) {
@@ -984,6 +990,8 @@ function processLoad(proc, callback) {
984
990
  let mem = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
985
991
  allcpuu = allcpuu + utime;
986
992
  allcpus = allcpus + stime;
993
+ // allcpuu += utime - (_process_cpu.list[pid] ? _process_cpu.list[pid].utime : 0);
994
+ // allcpus += stime - (_process_cpu.list[pid] ? _process_cpu.list[pid].stime : 0);
987
995
 
988
996
  procStats.push({
989
997
  pid: pid,
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.3",
3
+ "version": "5.10.7",
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)",