systeminformation 5.28.2 → 5.28.3

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/lib/processes.js +111 -120
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -52,7 +52,7 @@
52
52
  ```
53
53
  I wish you all a Merry Christmas and a peaceful New Year 2026.
54
54
 
55
- This is amazing. Started as a small project just for myself, it now has > 18,000
55
+ This is amazing. Started as a small project just for myself, it now has > 19,000
56
56
  lines of code, > 700 versions published, up to 15 mio downloads per month, > 450
57
57
  mio downloads overall. Top 10 NPM ranking for backend packages. Thank you to all
58
58
  who contributed to this project!
package/lib/processes.js CHANGED
@@ -934,82 +934,72 @@ function processes(callback) {
934
934
  try {
935
935
  util
936
936
  .powerShell(
937
- 'Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | fl'
937
+ 'Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | ConvertTo-Json -compress'
938
938
  )
939
939
  .then((stdout, error) => {
940
940
  if (!error) {
941
- let processSections = stdout.split(/\n\s*\n/);
942
- let procs = [];
943
- let procStats = [];
944
- let list_new = {};
941
+ const procs = [];
942
+ const procStats = [];
943
+ const list_new = {};
945
944
  let allcpuu = 0;
946
945
  let allcpus = 0;
947
- processSections.forEach((element) => {
948
- if (element.trim() !== '') {
949
- let lines = element.trim().split('\r\n');
950
- let pid = parseInt(util.getValue(lines, 'ProcessId', ':', true), 10);
951
- let parentPid = parseInt(util.getValue(lines, 'ParentProcessId', ':', true), 10);
952
- let statusValue = util.getValue(lines, 'ExecutionState', ':');
953
- let name = util.getValue(lines, 'Caption', ':', true);
954
- let commandLine = util.getValue(lines, 'CommandLine', ':', true);
955
- // get additional command line data
956
- let additionalCommand = false;
957
- lines.forEach((line) => {
958
- if (additionalCommand && line.toLowerCase().startsWith(' ')) {
959
- commandLine += ' ' + line.trim();
960
- } else {
961
- additionalCommand = false;
962
- }
963
- if (line.toLowerCase().startsWith('commandline')) {
964
- additionalCommand = true;
965
- }
966
- });
967
- let commandPath = util.getValue(lines, 'ExecutablePath', ':', true);
968
- let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
969
- let stime = parseInt(util.getValue(lines, 'KernelModeTime', ':', true), 10);
970
- let memw = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
971
- allcpuu = allcpuu + utime;
972
- allcpus = allcpus + stime;
973
- result.all++;
974
- if (!statusValue) {
975
- result.unknown++;
976
- }
977
- if (statusValue === '3') {
978
- result.running++;
979
- }
980
- if (statusValue === '4' || statusValue === '5') {
981
- result.blocked++;
982
- }
983
-
984
- procStats.push({
985
- pid: pid,
986
- utime: utime,
987
- stime: stime,
988
- cpu: 0,
989
- cpuu: 0,
990
- cpus: 0
991
- });
992
- procs.push({
993
- pid: pid,
994
- parentPid: parentPid,
995
- name: name,
996
- cpu: 0,
997
- cpuu: 0,
998
- cpus: 0,
999
- mem: (memw / os.totalmem()) * 100,
1000
- priority: parseInt(util.getValue(lines, 'Priority', ':', true), 10),
1001
- memVsz: parseInt(util.getValue(lines, 'PageFileUsage', ':', true), 10),
1002
- memRss: Math.floor(parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10) / 1024),
1003
- nice: 0,
1004
- started: util.getValue(lines, 'CreationDate', ':', true),
1005
- state: !statusValue ? _winStatusValues[0] : _winStatusValues[statusValue],
1006
- tty: '',
1007
- user: '',
1008
- command: commandLine || name,
1009
- path: commandPath,
1010
- params: ''
1011
- });
946
+ let processArray = [];
947
+ try {
948
+ stdout = stdout.trim().replace(/^\uFEFF/, '');
949
+ processArray = JSON.parse(stdout);
950
+ } catch {}
951
+ processArray.forEach((element) => {
952
+ const pid = element.ProcessId;
953
+ const parentPid = element.ParentProcessId;
954
+ const statusValue = element.ExecutionState || null;
955
+ const name = element.Caption;
956
+ const commandLine = element.CommandLine;
957
+ // get additional command line data
958
+ const commandPath = element.ExecutablePath;
959
+ const utime = element.UserModeTime;
960
+ const stime = element.KernelModeTime;
961
+ const memw = element.WorkingSetSize;
962
+ allcpuu = allcpuu + utime;
963
+ allcpus = allcpus + stime;
964
+ result.all++;
965
+ if (!statusValue) {
966
+ result.unknown++;
967
+ }
968
+ if (statusValue === '3') {
969
+ result.running++;
1012
970
  }
971
+ if (statusValue === '4' || statusValue === '5') {
972
+ result.blocked++;
973
+ }
974
+
975
+ procStats.push({
976
+ pid: pid,
977
+ utime: utime,
978
+ stime: stime,
979
+ cpu: 0,
980
+ cpuu: 0,
981
+ cpus: 0
982
+ });
983
+ procs.push({
984
+ pid: pid,
985
+ parentPid: parentPid,
986
+ name: name,
987
+ cpu: 0,
988
+ cpuu: 0,
989
+ cpus: 0,
990
+ mem: (memw / os.totalmem()) * 100,
991
+ priority: element.Priority | null,
992
+ memVsz: element.PageFileUsage || null,
993
+ memRss: Math.floor((element.WorkingSetSize || 0) / 1024),
994
+ nice: 0,
995
+ started: element.CreationDate,
996
+ state: statusValue ? _winStatusValues[statusValue] : _winStatusValues[0],
997
+ tty: '',
998
+ user: '',
999
+ command: commandLine || name,
1000
+ path: commandPath,
1001
+ params: ''
1002
+ });
1013
1003
  });
1014
1004
 
1015
1005
  result.sleeping = result.all - result.running - result.blocked - result.unknown;
@@ -1138,69 +1128,70 @@ function processLoad(proc, callback) {
1138
1128
  if (procSanitized && processes.length && processes[0] !== '------') {
1139
1129
  if (_windows) {
1140
1130
  try {
1141
- util.powerShell('Get-CimInstance Win32_Process | select ProcessId,Caption,UserModeTime,KernelModeTime,WorkingSetSize | fl').then((stdout, error) => {
1131
+ util.powerShell('Get-CimInstance Win32_Process | select ProcessId,Caption,UserModeTime,KernelModeTime,WorkingSetSize | ConvertTo-Json -compress').then((stdout, error) => {
1142
1132
  if (!error) {
1143
- let processSections = stdout.split(/\n\s*\n/);
1144
- let procStats = [];
1145
- let list_new = {};
1133
+ const procStats = [];
1134
+ const list_new = {};
1146
1135
  let allcpuu = 0;
1147
1136
  let allcpus = 0;
1137
+ let processArray = [];
1138
+ try {
1139
+ stdout = stdout.trim().replace(/^\uFEFF/, '');
1140
+ processArray = JSON.parse(stdout);
1141
+ } catch {}
1148
1142
 
1149
1143
  // go through all processes
1150
- processSections.forEach((element) => {
1151
- if (element.trim() !== '') {
1152
- let lines = element.trim().split('\r\n');
1153
- let pid = parseInt(util.getValue(lines, 'ProcessId', ':', true), 10);
1154
- let name = util.getValue(lines, 'Caption', ':', true);
1155
- let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
1156
- let stime = parseInt(util.getValue(lines, 'KernelModeTime', ':', true), 10);
1157
- let mem = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
1158
- allcpuu = allcpuu + utime;
1159
- allcpus = allcpus + stime;
1144
+ processArray.forEach((element) => {
1145
+ const pid = element.ProcessId;
1146
+ const name = element.Caption;
1147
+ const utime = element.UserModeTime;
1148
+ const stime = element.KernelModeTime;
1149
+ const mem = element.WorkingSetSize;
1150
+ allcpuu = allcpuu + utime;
1151
+ allcpus = allcpus + stime;
1160
1152
 
1161
- procStats.push({
1162
- pid: pid,
1163
- name,
1164
- utime: utime,
1165
- stime: stime,
1166
- cpu: 0,
1167
- cpuu: 0,
1168
- cpus: 0,
1169
- mem
1170
- });
1171
- let pname = '';
1172
- let inList = false;
1173
- processes.forEach((proc) => {
1174
- if (name.toLowerCase().indexOf(proc.toLowerCase()) >= 0 && !inList) {
1175
- inList = true;
1176
- pname = proc;
1153
+ procStats.push({
1154
+ pid: pid,
1155
+ name,
1156
+ utime: utime,
1157
+ stime: stime,
1158
+ cpu: 0,
1159
+ cpuu: 0,
1160
+ cpus: 0,
1161
+ mem
1162
+ });
1163
+ let pname = '';
1164
+ let inList = false;
1165
+ processes.forEach((proc) => {
1166
+ if (name.toLowerCase().indexOf(proc.toLowerCase()) >= 0 && !inList) {
1167
+ inList = true;
1168
+ pname = proc;
1169
+ }
1170
+ });
1171
+
1172
+ if (processesString === '*' || inList) {
1173
+ let processFound = false;
1174
+ result.forEach((item) => {
1175
+ if (item.proc.toLowerCase() === pname.toLowerCase()) {
1176
+ item.pids.push(pid);
1177
+ item.mem += (mem / os.totalmem()) * 100;
1178
+ processFound = true;
1177
1179
  }
1178
1180
  });
1179
-
1180
- if (processesString === '*' || inList) {
1181
- let processFound = false;
1182
- result.forEach((item) => {
1183
- if (item.proc.toLowerCase() === pname.toLowerCase()) {
1184
- item.pids.push(pid);
1185
- item.mem += (mem / os.totalmem()) * 100;
1186
- processFound = true;
1187
- }
1181
+ if (!processFound) {
1182
+ result.push({
1183
+ proc: pname,
1184
+ pid: pid,
1185
+ pids: [pid],
1186
+ cpu: 0,
1187
+ mem: (mem / os.totalmem()) * 100
1188
1188
  });
1189
- if (!processFound) {
1190
- result.push({
1191
- proc: pname,
1192
- pid: pid,
1193
- pids: [pid],
1194
- cpu: 0,
1195
- mem: (mem / os.totalmem()) * 100
1196
- });
1197
- }
1198
1189
  }
1199
1190
  }
1200
1191
  });
1201
1192
 
1202
- // add missing processes
1203
1193
  if (processesString !== '*') {
1194
+ // add missing processes
1204
1195
  let processesMissing = processes.filter((name) => procStats.filter((item) => item.name.toLowerCase().indexOf(name) >= 0).length === 0);
1205
1196
  processesMissing.forEach((procName) => {
1206
1197
  result.push({
@@ -1249,7 +1240,7 @@ function processLoad(proc, callback) {
1249
1240
  resolve(result);
1250
1241
  }
1251
1242
  });
1252
- } catch (e) {
1243
+ } catch {
1253
1244
  if (callback) {
1254
1245
  callback(result);
1255
1246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.28.2",
3
+ "version": "5.28.3",
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)",