processes() added user (windows)
This commit is contained in:
parent
582b62eef8
commit
eae041df50
@ -90,6 +90,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| 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.1 | 2026-01-05 | `fsSize()` support network attached storage (linux) |
|
||||||
| 5.29.0 | 2026-01-04 | `osInfo()` added OS code name (windows) |
|
| 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) |
|
| 5.28.10 | 2026-01-03 | `graphics()` fix logging nvidia-smi error (windows) |
|
||||||
|
|||||||
@ -185,6 +185,7 @@ si.cpu()
|
|||||||
|
|
||||||
(last 7 major and minor version releases)
|
(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.29.0: `osInfo()` added OS code name (windows)
|
||||||
- Version 5.28.0: `cpuTemperature()` added suppurt for macos-temperature-sensor (macOS)
|
- Version 5.28.0: `cpuTemperature()` added suppurt for macos-temperature-sensor (macOS)
|
||||||
- Version 5.27.0: `mem()` added reclaimable memory
|
- Version 5.27.0: `mem()` added reclaimable memory
|
||||||
|
|||||||
@ -57,6 +57,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<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>
|
<tr>
|
||||||
<th scope="row">5.29.1</th>
|
<th scope="row">5.29.1</th>
|
||||||
<td>2026-01-05</td>
|
<td>2026-01-05</td>
|
||||||
|
|||||||
@ -170,7 +170,7 @@
|
|||||||
<img class="logo" src="assets/logo.png" alt="logo">
|
<img class="logo" src="assets/logo.png" alt="logo">
|
||||||
<div class="title">systeminformation</div>
|
<div class="title">systeminformation</div>
|
||||||
<div class="subtitle"><span id="typed"></span> </div>
|
<div class="subtitle"><span id="typed"></span> </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>
|
<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>
|
||||||
<div class="down">
|
<div class="down">
|
||||||
|
|||||||
@ -459,7 +459,7 @@ si.currentLoad().then(data => console.log(data));</code></pre>
|
|||||||
<td>X</td>
|
<td>X</td>
|
||||||
<td>X</td>
|
<td>X</td>
|
||||||
<td>X</td>
|
<td>X</td>
|
||||||
<td></td>
|
<td>X</td>
|
||||||
<td>X</td>
|
<td>X</td>
|
||||||
<td>user who started process</td>
|
<td>user who started process</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -934,7 +934,11 @@ function processes(callback) {
|
|||||||
try {
|
try {
|
||||||
util
|
util
|
||||||
.powerShell(
|
.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) => {
|
.then((stdout, error) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
@ -959,6 +963,7 @@ function processes(callback) {
|
|||||||
const utime = element.UserModeTime;
|
const utime = element.UserModeTime;
|
||||||
const stime = element.KernelModeTime;
|
const stime = element.KernelModeTime;
|
||||||
const memw = element.WorkingSetSize;
|
const memw = element.WorkingSetSize;
|
||||||
|
const user = element.User;
|
||||||
allcpuu = allcpuu + utime;
|
allcpuu = allcpuu + utime;
|
||||||
allcpus = allcpus + stime;
|
allcpus = allcpus + stime;
|
||||||
result.all++;
|
result.all++;
|
||||||
@ -995,7 +1000,7 @@ function processes(callback) {
|
|||||||
started: element.CreationDate,
|
started: element.CreationDate,
|
||||||
state: statusValue ? _winStatusValues[statusValue] : _winStatusValues[0],
|
state: statusValue ? _winStatusValues[statusValue] : _winStatusValues[0],
|
||||||
tty: '',
|
tty: '',
|
||||||
user: '',
|
user,
|
||||||
command: commandLine || name,
|
command: commandLine || name,
|
||||||
path: commandPath,
|
path: commandPath,
|
||||||
params: ''
|
params: ''
|
||||||
|
|||||||
64
lib/users.js
64
lib/users.js
@ -16,7 +16,7 @@
|
|||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
const util = require('./util');
|
const util = require('./util');
|
||||||
|
|
||||||
let _platform = process.platform;
|
const _platform = process.platform;
|
||||||
|
|
||||||
const _linux = _platform === 'linux' || _platform === 'android';
|
const _linux = _platform === 'linux' || _platform === 'android';
|
||||||
const _darwin = _platform === 'darwin';
|
const _darwin = _platform === 'darwin';
|
||||||
@ -27,20 +27,20 @@ const _netbsd = _platform === 'netbsd';
|
|||||||
const _sunos = _platform === 'sunos';
|
const _sunos = _platform === 'sunos';
|
||||||
|
|
||||||
function parseUsersLinux(lines, phase) {
|
function parseUsersLinux(lines, phase) {
|
||||||
let result = [];
|
const result = [];
|
||||||
let result_who = [];
|
const result_who = [];
|
||||||
let result_w = {};
|
const result_w = {};
|
||||||
let w_first = true;
|
let w_first = true;
|
||||||
let w_header = [];
|
let w_header = [];
|
||||||
let w_pos = [];
|
const w_pos = [];
|
||||||
let who_line = {};
|
let who_line = {};
|
||||||
|
|
||||||
let is_whopart = true;
|
let is_whopart = true;
|
||||||
lines.forEach(function (line) {
|
lines.forEach((line) => {
|
||||||
if (line === '---') {
|
if (line === '---') {
|
||||||
is_whopart = false;
|
is_whopart = false;
|
||||||
} else {
|
} else {
|
||||||
let l = line.replace(/ +/g, ' ').split(' ');
|
const l = line.replace(/ +/g, ' ').split(' ');
|
||||||
|
|
||||||
// who part
|
// who part
|
||||||
if (is_whopart) {
|
if (is_whopart) {
|
||||||
@ -55,11 +55,13 @@ function parseUsersLinux(lines, phase) {
|
|||||||
// w part
|
// w part
|
||||||
if (w_first) {
|
if (w_first) {
|
||||||
// header
|
// header
|
||||||
|
if (line[0] !== ' ') {
|
||||||
w_header = l;
|
w_header = l;
|
||||||
w_header.forEach(function (item) {
|
w_header.forEach((item) => {
|
||||||
w_pos.push(line.indexOf(item));
|
w_pos.push(line.indexOf(item));
|
||||||
});
|
});
|
||||||
w_first = false;
|
w_first = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// split by w_pos
|
// split by w_pos
|
||||||
result_w.user = line.substring(w_pos[0], w_pos[1] - 1).trim();
|
result_w.user = line.substring(w_pos[0], w_pos[1] - 1).trim();
|
||||||
@ -71,10 +73,14 @@ function parseUsersLinux(lines, phase) {
|
|||||||
.trim();
|
.trim();
|
||||||
result_w.command = line.substring(w_pos[7], 1000).trim();
|
result_w.command = line.substring(w_pos[7], 1000).trim();
|
||||||
// find corresponding 'who' line
|
// 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;
|
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({
|
result.push({
|
||||||
user: who_line[0].user,
|
user: who_line[0].user,
|
||||||
tty: who_line[0].tty,
|
tty: who_line[0].tty,
|
||||||
@ -96,17 +102,17 @@ function parseUsersLinux(lines, phase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseUsersDarwin(lines) {
|
function parseUsersDarwin(lines) {
|
||||||
let result = [];
|
const result = [];
|
||||||
let result_who = [];
|
const result_who = [];
|
||||||
let result_w = {};
|
const result_w = {};
|
||||||
let who_line = {};
|
let who_line = {};
|
||||||
|
|
||||||
let is_whopart = true;
|
let is_whopart = true;
|
||||||
lines.forEach(function (line) {
|
lines.forEach((line) => {
|
||||||
if (line === '---') {
|
if (line === '---') {
|
||||||
is_whopart = false;
|
is_whopart = false;
|
||||||
} else {
|
} else {
|
||||||
let l = line.replace(/ +/g, ' ').split(' ');
|
const l = line.replace(/ +/g, ' ').split(' ');
|
||||||
|
|
||||||
// who part
|
// who part
|
||||||
if (is_whopart) {
|
if (is_whopart) {
|
||||||
@ -132,9 +138,7 @@ function parseUsersDarwin(lines) {
|
|||||||
result_w.ip = l[2] !== '-' ? l[2] : '';
|
result_w.ip = l[2] !== '-' ? l[2] : '';
|
||||||
result_w.command = l.slice(5, 1000).join(' ');
|
result_w.command = l.slice(5, 1000).join(' ');
|
||||||
// find corresponding 'who' line
|
// find corresponding 'who' line
|
||||||
who_line = result_who.filter(function (obj) {
|
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));
|
||||||
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);
|
|
||||||
});
|
|
||||||
if (who_line.length === 1) {
|
if (who_line.length === 1) {
|
||||||
result.push({
|
result.push({
|
||||||
user: who_line[0].user,
|
user: who_line[0].user,
|
||||||
@ -158,13 +162,13 @@ function users(callback) {
|
|||||||
|
|
||||||
// linux
|
// linux
|
||||||
if (_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) {
|
if (!error) {
|
||||||
// lines / split
|
// lines / split
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
result = parseUsersLinux(lines, 1);
|
result = parseUsersLinux(lines, 1);
|
||||||
if (result.length === 0) {
|
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) {
|
if (!error) {
|
||||||
// lines / split
|
// lines / split
|
||||||
lines = stdout.toString().split('\n');
|
lines = stdout.toString().split('\n');
|
||||||
@ -190,10 +194,10 @@ function users(callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_freebsd || _openbsd || _netbsd) {
|
if (_freebsd || _openbsd || _netbsd) {
|
||||||
exec('who; echo "---"; w -ih', function (error, stdout) {
|
exec('who; echo "---"; w -ih', (error, stdout) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
// lines / split
|
// lines / split
|
||||||
let lines = stdout.toString().split('\n');
|
const lines = stdout.toString().split('\n');
|
||||||
result = parseUsersDarwin(lines);
|
result = parseUsersDarwin(lines);
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@ -203,10 +207,10 @@ function users(callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_sunos) {
|
if (_sunos) {
|
||||||
exec('who; echo "---"; w -h', function (error, stdout) {
|
exec('who; echo "---"; w -h', (error, stdout) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
// lines / split
|
// lines / split
|
||||||
let lines = stdout.toString().split('\n');
|
const lines = stdout.toString().split('\n');
|
||||||
result = parseUsersDarwin(lines);
|
result = parseUsersDarwin(lines);
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@ -217,10 +221,10 @@ function users(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_darwin) {
|
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) {
|
if (!error) {
|
||||||
// lines / split
|
// lines / split
|
||||||
let lines = stdout.toString().split('\n');
|
const lines = stdout.toString().split('\n');
|
||||||
result = parseUsersDarwin(lines);
|
result = parseUsersDarwin(lines);
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@ -239,10 +243,10 @@ function users(callback) {
|
|||||||
util.powerShell(cmd).then((data) => {
|
util.powerShell(cmd).then((data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
data = data.split('#-#-#-#');
|
data = data.split('#-#-#-#');
|
||||||
let sessions = parseWinSessions((data[0] || '').split(/\n\s*\n/));
|
const sessions = parseWinSessions((data[0] || '').split(/\n\s*\n/));
|
||||||
let loggedons = parseWinLoggedOn((data[1] || '').split(/\n\s*\n/));
|
const loggedons = parseWinLoggedOn((data[1] || '').split(/\n\s*\n/));
|
||||||
let queryUser = parseWinUsersQuery((data[3] || '').split('\r\n'));
|
const queryUser = parseWinUsersQuery((data[3] || '').split('\r\n'));
|
||||||
let users = parseWinUsers((data[2] || '').split(/\n\s*\n/), queryUser);
|
const users = parseWinUsers((data[2] || '').split(/\n\s*\n/), queryUser);
|
||||||
for (let id in loggedons) {
|
for (let id in loggedons) {
|
||||||
if ({}.hasOwnProperty.call(loggedons, id)) {
|
if ({}.hasOwnProperty.call(loggedons, id)) {
|
||||||
loggedons[id].dateTime = {}.hasOwnProperty.call(sessions, id) ? sessions[id] : '';
|
loggedons[id].dateTime = {}.hasOwnProperty.call(sessions, id) ? sessions[id] : '';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user