From eae041df501c289601fef7d548baa44553712e75 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Tue, 6 Jan 2026 07:16:50 +0100 Subject: [PATCH] processes() added user (windows) --- CHANGELOG.md | 1 + README.md | 1 + docs/history.html | 5 +++ docs/index.html | 2 +- docs/processes.html | 2 +- lib/processes.js | 9 ++++-- lib/users.js | 76 ++++++++++++++++++++++++--------------------- 7 files changed, 56 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce7f579..28da3eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | ------- | ---------- | --------------------------------------------------------------------------------------------------- | +| 5.30.0 | 2026-01-06 | `processes()` added user (windows) | | 5.29.1 | 2026-01-05 | `fsSize()` support network attached storage (linux) | | 5.29.0 | 2026-01-04 | `osInfo()` added OS code name (windows) | | 5.28.10 | 2026-01-03 | `graphics()` fix logging nvidia-smi error (windows) | diff --git a/README.md b/README.md index a8268b4..3a865b6 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,7 @@ si.cpu() (last 7 major and minor version releases) +- Version 5.30.0: `processes()` added user (windows) - Version 5.29.0: `osInfo()` added OS code name (windows) - Version 5.28.0: `cpuTemperature()` added suppurt for macos-temperature-sensor (macOS) - Version 5.27.0: `mem()` added reclaimable memory diff --git a/docs/history.html b/docs/history.html index 97c1270..782a7df 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@ + + 5.30.0 + 2026-01-06 + processes() added user (windows) + 5.29.1 2026-01-05 diff --git a/docs/index.html b/docs/index.html index aeb318f..71351a6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.29.1
+
New Version: 5.30.0
diff --git a/docs/processes.html b/docs/processes.html index 083e568..cb2684d 100644 --- a/docs/processes.html +++ b/docs/processes.html @@ -459,7 +459,7 @@ si.currentLoad().then(data => console.log(data)); X X X - + X X user who started process diff --git a/lib/processes.js b/lib/processes.js index 772cea1..01f24ec 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -934,7 +934,11 @@ function processes(callback) { try { util .powerShell( - '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' + `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")}}, + @{n="User";e={$OwnerInfo = Invoke-CimMethod -InputObject $_ -MethodName GetOwner + if($OwnerInfo.ReturnValue -eq 0) {"$($OwnerInfo.Domain)\\$($OwnerInfo.User)"} else {""} + }} | ConvertTo-Json -compress` ) .then((stdout, error) => { if (!error) { @@ -959,6 +963,7 @@ function processes(callback) { const utime = element.UserModeTime; const stime = element.KernelModeTime; const memw = element.WorkingSetSize; + const user = element.User; allcpuu = allcpuu + utime; allcpus = allcpus + stime; result.all++; @@ -995,7 +1000,7 @@ function processes(callback) { started: element.CreationDate, state: statusValue ? _winStatusValues[statusValue] : _winStatusValues[0], tty: '', - user: '', + user, command: commandLine || name, path: commandPath, params: '' diff --git a/lib/users.js b/lib/users.js index 873bcec..dd0d577 100644 --- a/lib/users.js +++ b/lib/users.js @@ -16,7 +16,7 @@ const exec = require('child_process').exec; const util = require('./util'); -let _platform = process.platform; +const _platform = process.platform; const _linux = _platform === 'linux' || _platform === 'android'; const _darwin = _platform === 'darwin'; @@ -27,20 +27,20 @@ const _netbsd = _platform === 'netbsd'; const _sunos = _platform === 'sunos'; function parseUsersLinux(lines, phase) { - let result = []; - let result_who = []; - let result_w = {}; + const result = []; + const result_who = []; + const result_w = {}; let w_first = true; let w_header = []; - let w_pos = []; + const w_pos = []; let who_line = {}; let is_whopart = true; - lines.forEach(function (line) { + lines.forEach((line) => { if (line === '---') { is_whopart = false; } else { - let l = line.replace(/ +/g, ' ').split(' '); + const l = line.replace(/ +/g, ' ').split(' '); // who part if (is_whopart) { @@ -55,11 +55,13 @@ function parseUsersLinux(lines, phase) { // w part if (w_first) { // header - w_header = l; - w_header.forEach(function (item) { - w_pos.push(line.indexOf(item)); - }); - w_first = false; + if (line[0] !== ' ') { + w_header = l; + w_header.forEach((item) => { + w_pos.push(line.indexOf(item)); + }); + w_first = false; + } } else { // split by w_pos result_w.user = line.substring(w_pos[0], w_pos[1] - 1).trim(); @@ -71,10 +73,14 @@ function parseUsersLinux(lines, phase) { .trim(); result_w.command = line.substring(w_pos[7], 1000).trim(); // find corresponding 'who' line - who_line = result_who.filter(function (obj) { - return obj.user.substring(0, 8).trim() === result_w.user && obj.tty === result_w.tty; - }); - if (who_line.length === 1) { + if (result_who.length || phase === 1) { + who_line = result_who.filter((obj) => { + return obj.user.substring(0, 8).trim() === result_w.user && obj.tty === result_w.tty; + }); + } else { + who_line = [{ user: result_w.user, tty: result_w.tty, date: '', time: '', ip: '' }]; + } + if (who_line.length === 1 && who_line[0].user !== '') { result.push({ user: who_line[0].user, tty: who_line[0].tty, @@ -96,17 +102,17 @@ function parseUsersLinux(lines, phase) { } function parseUsersDarwin(lines) { - let result = []; - let result_who = []; - let result_w = {}; + const result = []; + const result_who = []; + const result_w = {}; let who_line = {}; let is_whopart = true; - lines.forEach(function (line) { + lines.forEach((line) => { if (line === '---') { is_whopart = false; } else { - let l = line.replace(/ +/g, ' ').split(' '); + const l = line.replace(/ +/g, ' ').split(' '); // who part if (is_whopart) { @@ -132,9 +138,7 @@ function parseUsersDarwin(lines) { result_w.ip = l[2] !== '-' ? l[2] : ''; result_w.command = l.slice(5, 1000).join(' '); // find corresponding 'who' line - who_line = result_who.filter(function (obj) { - return obj.user.substring(0, 10) === result_w.user.substring(0, 10) && (obj.tty.substring(3, 1000) === result_w.tty || obj.tty === result_w.tty); - }); + who_line = result_who.filter((obj) => obj.user.substring(0, 10) === result_w.user.substring(0, 10) && (obj.tty.substring(3, 1000) === result_w.tty || obj.tty === result_w.tty)); if (who_line.length === 1) { result.push({ user: who_line[0].user, @@ -158,13 +162,13 @@ function users(callback) { // linux if (_linux) { - exec('export LC_ALL=C; who --ips; echo "---"; w; unset LC_ALL | tail -n +2', function (error, stdout) { + exec('export LC_ALL=C; who --ips; echo "---"; w; unset LC_ALL | tail -n +2', (error, stdout) => { if (!error) { // lines / split let lines = stdout.toString().split('\n'); result = parseUsersLinux(lines, 1); if (result.length === 0) { - exec('who; echo "---"; w | tail -n +2', function (error, stdout) { + exec('who; echo "---"; w | tail -n +2', (error, stdout) => { if (!error) { // lines / split lines = stdout.toString().split('\n'); @@ -190,10 +194,10 @@ function users(callback) { }); } if (_freebsd || _openbsd || _netbsd) { - exec('who; echo "---"; w -ih', function (error, stdout) { + exec('who; echo "---"; w -ih', (error, stdout) => { if (!error) { // lines / split - let lines = stdout.toString().split('\n'); + const lines = stdout.toString().split('\n'); result = parseUsersDarwin(lines); } if (callback) { @@ -203,10 +207,10 @@ function users(callback) { }); } if (_sunos) { - exec('who; echo "---"; w -h', function (error, stdout) { + exec('who; echo "---"; w -h', (error, stdout) => { if (!error) { // lines / split - let lines = stdout.toString().split('\n'); + const lines = stdout.toString().split('\n'); result = parseUsersDarwin(lines); } if (callback) { @@ -217,10 +221,10 @@ function users(callback) { } if (_darwin) { - exec('export LC_ALL=C; who; echo "---"; w -ih; unset LC_ALL', function (error, stdout) { + exec('export LC_ALL=C; who; echo "---"; w -ih; unset LC_ALL', (error, stdout) => { if (!error) { // lines / split - let lines = stdout.toString().split('\n'); + const lines = stdout.toString().split('\n'); result = parseUsersDarwin(lines); } if (callback) { @@ -239,10 +243,10 @@ function users(callback) { util.powerShell(cmd).then((data) => { if (data) { data = data.split('#-#-#-#'); - let sessions = parseWinSessions((data[0] || '').split(/\n\s*\n/)); - let loggedons = parseWinLoggedOn((data[1] || '').split(/\n\s*\n/)); - let queryUser = parseWinUsersQuery((data[3] || '').split('\r\n')); - let users = parseWinUsers((data[2] || '').split(/\n\s*\n/), queryUser); + const sessions = parseWinSessions((data[0] || '').split(/\n\s*\n/)); + const loggedons = parseWinLoggedOn((data[1] || '').split(/\n\s*\n/)); + const queryUser = parseWinUsersQuery((data[3] || '').split('\r\n')); + const users = parseWinUsers((data[2] || '').split(/\n\s*\n/), queryUser); for (let id in loggedons) { if ({}.hasOwnProperty.call(loggedons, id)) { loggedons[id].dateTime = {}.hasOwnProperty.call(sessions, id) ? sessions[id] : '';