processes() added user (windows)

This commit is contained in:
Sebastian Hildebrandt 2026-01-06 07:16:50 +01:00
parent 582b62eef8
commit eae041df50
7 changed files with 56 additions and 40 deletions

View File

@ -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) |

View File

@ -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

View File

@ -57,6 +57,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.30.0</th>
<td>2026-01-06</td>
<td><span class="code">processes()</span> added user (windows)</td>
</tr>
<tr>
<th scope="row">5.29.1</th>
<td>2026-01-05</td>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png" alt="logo">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.29.1</span></div>
<div class="version">New Version: <span id="version">5.30.0</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">

View File

@ -459,7 +459,7 @@ si.currentLoad().then(data => console.log(data));</code></pre>
<td>X</td>
<td>X</td>
<td>X</td>
<td></td>
<td>X</td>
<td>X</td>
<td>user who started process</td>
</tr>

View File

@ -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: ''

View File

@ -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
if (line[0] !== ' ') {
w_header = l;
w_header.forEach(function (item) {
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) {
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;
});
if (who_line.length === 1) {
} 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] : '';