wmic to powershell transition completed, smaller changes and fixes

This commit is contained in:
Sebastian Hildebrandt 2021-11-11 10:14:10 +01:00
parent 42dc41a892
commit 47d3a97545
13 changed files with 3778 additions and 3660 deletions

View File

@ -163,6 +163,7 @@ Full function reference with examples can be found at [https://systeminformation
| | version | X | X | X | X | | version | | | version | X | X | X | X | | version |
| | releaseDate | X | X | | X | | release date | | | releaseDate | X | X | | X | | release date |
| | revision | X | X | | X | | revision | | | revision | X | X | | X | | revision |
| | serial | X | | | X | | serial |
| si.baseboard(cb) | {...} | X | X | X | X | | baseboard information | | si.baseboard(cb) | {...} | X | X | X | X | | baseboard information |
| | manufacturer | X | X | X | X | | e.g. 'ASUS' | | | manufacturer | X | X | X | X | | e.g. 'ASUS' |
| | model | X | X | X | X | | model / product name | | | model | X | X | X | X | | model / product name |

View File

@ -205,7 +205,7 @@
<td>X</td> <td>X</td>
<td></td> <td></td>
<td></td> <td></td>
<td>MUT maximum transmission unit</td> <td>MTU maximum transmission unit</td>
</tr> </tr>
<tr> <tr>
<td></td> <td></td>

View File

@ -293,6 +293,16 @@ si.uuid().then(data => console.log(data));</code></pre class="example">
<td></td> <td></td>
<td>revision</td> <td>revision</td>
</tr> </tr>
<tr>
<td></td>
<td>serial</td>
<td>X</td>
<td></td>
<td></td>
<td>X</td>
<td></td>
<td>serial</td>
</tr>
<tr> <tr>
<td></td> <td></td>
<td>language</td> <td>language</td>
@ -588,4 +598,4 @@ si.chassis().then(data => console.log(data));</code></pre class="example">
</script> </script>
</body> </body>
</html> </html>

View File

@ -160,7 +160,7 @@ module.exports = function (callback) {
} }
} }
if (_freebsd || _openbsd || _netbsd) { if (_freebsd || _openbsd || _netbsd) {
exec('sysctl hw.acpi.battery hw.acpi.acline', function (error, stdout) { exec('sysctl -i hw.acpi.battery hw.acpi.acline', function (error, stdout) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
const batteries = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.units'), 10); const batteries = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.units'), 10);
const percent = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.life'), 10); const percent = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.life'), 10);

View File

@ -126,24 +126,28 @@ function fsSize(callback) {
} }
if (_windows) { if (_windows) {
try { try {
util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout) => { // util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout) => {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); util.powerShell('Get-WmiObject Win32_logicaldisk | fl *').then((stdout, error) => {
lines.forEach(function (line) { if (!error) {
if (line !== '') { let devices = stdout.toString().split(/\n\s*\n/);
line = line.trim().split(/\s\s+/); devices.forEach(function (device) {
if (line.length >= 4 && parseInt(line[3], 10)) { let lines = device.split('\r\n');
const size = util.toInt(util.getValue(lines, 'size', ':'));
const free = util.toInt(util.getValue(lines, 'freespace', ':'));
const caption = util.getValue(lines, 'caption', ':');
if (size) {
data.push({ data.push({
fs: line[0], fs: caption,
type: line[1], type: util.getValue(lines, 'filesystem', ':'),
size: parseInt(line[3], 10), size,
used: parseInt(line[3], 10) - parseInt(line[2], 10), used: size - free,
available: parseInt(line[2], 10), available: free,
use: parseFloat(((100.0 * (parseInt(line[3]) - parseInt(line[2]))) / parseInt(line[3])).toFixed(2)), use: parseFloat(((100.0 * (size - free)) / size).toFixed(2)),
mount: line[0] mount: caption
}); });
} }
} });
}); }
if (callback) { if (callback) {
callback(data); callback(data);
} }
@ -173,12 +177,12 @@ function fsOpenFiles(callback) {
available: null available: null
}; };
if (_freebsd || _openbsd || _netbsd || _darwin) { if (_freebsd || _openbsd || _netbsd || _darwin) {
let cmd = 'sysctl -a | grep \'kern.*files\''; let cmd = 'sysctl -i kern.maxfiles kern.num_files kern.open_files';
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) { exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
result.max = parseInt(util.getValue(lines, 'kern.maxfiles', ':'), 10); result.max = parseInt(util.getValue(lines, 'kern.maxfiles', ':'), 10);
result.allocated = parseInt(util.getValue(lines, 'kern.num_files', ':'), 10); result.allocated = parseInt(util.getValue(lines, 'kern.num_files', ':'), 10) || parseInt(util.getValue(lines, 'kern.open_files', ':'), 10);
result.available = result.max - result.allocated; result.available = result.max - result.allocated;
} }
if (callback) { if (callback) {
@ -776,37 +780,37 @@ function diskLayout(callback) {
function getVendorFromModel(model) { function getVendorFromModel(model) {
const diskManufacturers = [ const diskManufacturers = [
{ pattern: '^WESTERN.+', manufacturer: 'Western Digital' }, { pattern: 'WESTERN.*', manufacturer: 'Western Digital' },
{ pattern: '^WDC.+', manufacturer: 'Western Digital' }, { pattern: '^WDC.*', manufacturer: 'Western Digital' },
{ pattern: 'WD.+', manufacturer: 'Western Digital' }, { pattern: 'WD.*', manufacturer: 'Western Digital' },
{ pattern: '^TOSHIBA.+', manufacturer: 'Toshiba' }, { pattern: 'TOSHIBA.*', manufacturer: 'Toshiba' },
{ pattern: '^HITACHI.+', manufacturer: 'Hitachi' }, { pattern: 'HITACHI.*', manufacturer: 'Hitachi' },
{ pattern: '^IC.+', manufacturer: 'Hitachi' }, { pattern: '^IC.*', manufacturer: 'Hitachi' },
{ pattern: '^HTS.+', manufacturer: 'Hitachi' }, { pattern: '^HTS.*', manufacturer: 'Hitachi' },
{ pattern: '^SANDISK.+', manufacturer: 'SanDisk' }, { pattern: 'SANDISK.*', manufacturer: 'SanDisk' },
{ pattern: '^KINGSTON.+', manufacturer: 'Kingston Technology' }, { pattern: 'KINGSTON.*', manufacturer: 'Kingston Technology' },
{ pattern: '^SONY.+', manufacturer: 'Sony' }, { pattern: '^SONY.*', manufacturer: 'Sony' },
{ pattern: '^TRANSCEND.+', manufacturer: 'Transcend' }, { pattern: 'TRANSCEND.*', manufacturer: 'Transcend' },
{ pattern: 'SAMSUNG.+', manufacturer: 'Samsung' }, { pattern: 'SAMSUNG.*', manufacturer: 'Samsung' },
{ pattern: '^ST(?!I\\ ).+', manufacturer: 'Seagate' }, { pattern: '^ST(?!I\\ ).*', manufacturer: 'Seagate' },
{ pattern: '^STI\\ .+', manufacturer: 'SimpleTech' }, { pattern: '^STI\\ .*', manufacturer: 'SimpleTech' },
{ pattern: '^D...-.+', manufacturer: 'IBM' }, { pattern: '^D...-.*', manufacturer: 'IBM' },
{ pattern: '^IBM.+', manufacturer: 'IBM' }, { pattern: '^IBM.*', manufacturer: 'IBM' },
{ pattern: '^FUJITSU.+', manufacturer: 'Fujitsu' }, { pattern: '^FUJITSU.*', manufacturer: 'Fujitsu' },
{ pattern: '^MP.+', manufacturer: 'Fujitsu' }, { pattern: '^MP.*', manufacturer: 'Fujitsu' },
{ pattern: '^MK.+', manufacturer: 'Toshiba' }, { pattern: '^MK.*', manufacturer: 'Toshiba' },
{ pattern: '^MAXTOR.+', manufacturer: 'Maxtor' }, { pattern: 'MAXTO.*', manufacturer: 'Maxtor' },
{ pattern: '^Pioneer.+', manufacturer: 'Pioneer' }, { pattern: 'PIONEER.*', manufacturer: 'Pioneer' },
{ pattern: '^PHILIPS.+', manufacturer: 'Philips' }, { pattern: 'PHILIPS.*', manufacturer: 'Philips' },
{ pattern: '^QUANTUM.+', manufacturer: 'Quantum Technology' }, { pattern: 'QUANTUM.*', manufacturer: 'Quantum Technology' },
{ pattern: 'FIREBALL.+', manufacturer: 'Quantum Technology' }, { pattern: 'FIREBALL.*', manufacturer: 'Quantum Technology' },
{ pattern: '^VBOX.+', manufacturer: 'VirtualBox' }, { pattern: '^VBOX.*', manufacturer: 'VirtualBox' },
{ pattern: 'CORSAIR.+', manufacturer: 'Corsair Components' }, { pattern: 'CORSAIR.*', manufacturer: 'Corsair Components' },
{ pattern: 'CRUCIAL.+', manufacturer: 'Crucial' }, { pattern: 'CRUCIAL.*', manufacturer: 'Crucial' },
{ pattern: 'ECM.+', manufacturer: 'ECM' }, { pattern: 'ECM.*', manufacturer: 'ECM' },
{ pattern: 'INTEL.+', manufacturer: 'INTEL' }, { pattern: 'INTEL.*', manufacturer: 'INTEL' },
{ pattern: '.+EVO', manufacturer: 'Samsung' }, { pattern: 'EVO.*', manufacturer: 'Samsung' },
{ pattern: 'APPLE.+', manufacturer: 'Apple' }, { pattern: 'APPLE.*', manufacturer: 'Apple' },
]; ];
let result = ''; let result = '';

View File

@ -181,7 +181,7 @@ function graphics(callback) {
connection: ((connectionType.indexOf('_internal') > -1) ? 'Internal' : ((connectionType.indexOf('_displayport') > -1) ? 'Display Port' : ((connectionType.indexOf('_hdmi') > -1) ? 'HDMI' : null))), connection: ((connectionType.indexOf('_internal') > -1) ? 'Internal' : ((connectionType.indexOf('_displayport') > -1) ? 'Display Port' : ((connectionType.indexOf('_hdmi') > -1) ? 'HDMI' : null))),
sizeX: null, sizeX: null,
sizeY: null, sizeY: null,
pixelDepth: (pixelDepthString === 'CGSThirtyBitColor' ? 30 : (pixelDepthString === 'CGSThirtytwoBitColor' ? 32 : (pixelDepthString === 'CGSTwentyfourBitColor' ? 24 : ''))), pixelDepth: (pixelDepthString === 'CGSThirtyBitColor' ? 30 : (pixelDepthString === 'CGSThirtytwoBitColor' ? 32 : (pixelDepthString === 'CGSTwentyfourBitColor' ? 24 : null))),
resolutionX: pixelParts.length > 1 ? parseInt(pixelParts[0], 10) : null, resolutionX: pixelParts.length > 1 ? parseInt(pixelParts[0], 10) : null,
resolutionY: pixelParts.length > 1 ? parseInt(pixelParts[1], 10) : null, resolutionY: pixelParts.length > 1 ? parseInt(pixelParts[1], 10) : null,
currentResX: currentResolution.length > 1 ? parseInt(currentResolution[0], 10) : null, currentResX: currentResolution.length > 1 ? parseInt(currentResolution[0], 10) : null,
@ -860,7 +860,7 @@ function graphics(callback) {
if (_pixelDepth) { if (_pixelDepth) {
result.displays[0].pixelDepth = _pixelDepth; result.displays[0].pixelDepth = _pixelDepth;
} }
if (_refreshRate && !result.displays[0].refreshRate) { if (_refreshRate && !result.displays[0].currentRefreshRate) {
result.displays[0].currentRefreshRate = _refreshRate; result.displays[0].currentRefreshRate = _refreshRate;
} }
} }

46
lib/index.d.ts vendored
View File

@ -38,6 +38,7 @@ export namespace Systeminformation {
version: string; version: string;
releaseDate: string; releaseDate: string;
revision: string; revision: string;
serial?: string;
language?: string; language?: string;
features?: string[]; features?: string[];
} }
@ -302,7 +303,7 @@ export namespace Systeminformation {
deviceId?: string; deviceId?: string;
bus: string; bus: string;
busAddress?: string; busAddress?: string;
vram: number; vram: number | null;
vramDynamic: boolean; vramDynamic: boolean;
external?: boolean; external?: boolean;
cores?: number; cores?: number;
@ -311,6 +312,7 @@ export namespace Systeminformation {
driverVersion?: string; driverVersion?: string;
name?: string; name?: string;
pciBus?: string; pciBus?: string;
pciID?: string;
fanSpeed?: number; fanSpeed?: number;
memoryTotal?: number; memoryTotal?: number;
memoryUsed?: number; memoryUsed?: number;
@ -327,21 +329,25 @@ export namespace Systeminformation {
interface GraphicsDisplayData { interface GraphicsDisplayData {
vendor: string; vendor: string;
vendorId: string | null;
model: string; model: string;
deviceName: string; productionYear: number | null;
serial: string | null;
deviceName: string | null;
displayId: string | null;
main: boolean; main: boolean;
builtin: boolean; builtin: boolean;
connection: string; connection: string | null;
sizeX: number; sizeX: number | null;
sizeY: number; sizeY: number | null;
pixelDepth: number; pixelDepth: number | null;
resolutionX: number; resolutionX: number | null;
resolutionY: number; resolutionY: number | null;
currentResX: number; currentResX: number | null;
currentResY: number; currentResY: number | null;
positionX: number; positionX: number;
positionY: number; positionY: number;
currentRefreshRate: number; currentRefreshRate: number | null;
} }
// 4. Operating System // 4. Operating System
@ -452,9 +458,9 @@ export namespace Systeminformation {
rx: number; rx: number;
wx: number; wx: number;
tx: number; tx: number;
rx_sec: number; rx_sec: number | null;
wx_sec: number; wx_sec: number | null;
tx_sec: number; tx_sec: number | null;
ms: number; ms: number;
} }
@ -462,9 +468,15 @@ export namespace Systeminformation {
rIO: number; rIO: number;
wIO: number; wIO: number;
tIO: number; tIO: number;
rIO_sec: number; rIO_sec: number | null;
wIO_sec: number; wIO_sec: number | null;
tIO_sec: number; tIO_sec: number | null;
rWaitTime: number;
wWaitTime: number;
tWaitTime: number;
rWaitPercent: number | null;
wWaitPercent: number | null;
tWaitPercent: number | null;
ms: number; ms: number;
} }

View File

@ -198,7 +198,7 @@ function mem(callback) {
}); });
} }
if (_freebsd || _openbsd || _netbsd) { if (_freebsd || _openbsd || _netbsd) {
exec('/sbin/sysctl -a 2>/dev/null | grep -E "hw.realmem|hw.physmem|vm.stats.vm.v_page_count|vm.stats.vm.v_wire_count|vm.stats.vm.v_active_count|vm.stats.vm.v_inactive_count|vm.stats.vm.v_cache_count|vm.stats.vm.v_free_count|vm.stats.vm.v_page_size"', function (error, stdout) { exec('/sbin/sysctl hw.realmem hw.physmem vm.stats.vm.v_page_count vm.stats.vm.v_wire_count vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count vm.stats.vm.v_page_size', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
const pagesize = parseInt(util.getValue(lines, 'vm.stats.vm.v_page_size'), 10); const pagesize = parseInt(util.getValue(lines, 'vm.stats.vm.v_page_size'), 10);
@ -331,7 +331,7 @@ function memLayout(callback) {
serialNum: util.getValue(lines, 'Serial Number:'), serialNum: util.getValue(lines, 'Serial Number:'),
voltageConfigured: parseFloat(util.getValue(lines, 'Configured Voltage:')) || null, voltageConfigured: parseFloat(util.getValue(lines, 'Configured Voltage:')) || null,
voltageMin: parseFloat(util.getValue(lines, 'Minimum Voltage:')) || null, voltageMin: parseFloat(util.getValue(lines, 'Minimum Voltage:')) || null,
voltageMax: parseFloat(util.getValue(lines, 'Maximum Voltage:'))|| null, voltageMax: parseFloat(util.getValue(lines, 'Maximum Voltage:')) || null,
}); });
} else { } else {
result.push({ result.push({

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -283,16 +283,21 @@ function users(callback) {
} }
if (_windows) { if (_windows) {
try { try {
const workload = []; // const workload = [];
// workload.push(util.powerShell('Get-CimInstance -ClassName Win32_Account | fl *')); // // workload.push(util.powerShell('Get-CimInstance -ClassName Win32_Account | fl *'));
workload.push(util.powerShell('Get-WmiObject Win32_LogonSession | fl *')); // workload.push(util.powerShell('Get-WmiObject Win32_LogonSession | fl *'));
workload.push(util.powerShell('Get-WmiObject Win32_LoggedOnUser | fl *')); // workload.push(util.powerShell('Get-WmiObject Win32_LoggedOnUser | fl *'));
workload.push(util.powerShell('Get-WmiObject Win32_Process -Filter "name=\'explorer.exe\'" | Select @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl')); // workload.push(util.powerShell('Get-WmiObject Win32_Process -Filter "name=\'explorer.exe\'" | Select @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl'));
Promise.all( // Promise.all(
workload // workload
).then(data => { // ).then(data => {
let cmd = 'Get-WmiObject Win32_LogonSession | fl *' + '; echo \'#-#-#-#\';';
cmd += 'Get-WmiObject Win32_LoggedOnUser | fl *' + '; echo \'#-#-#-#\';';
cmd += 'Get-WmiObject Win32_Process -Filter "name=\'explorer.exe\'" | Select @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl';
util.powerShell(cmd).then(data => {
// controller + vram // controller + vram
// let accounts = parseWinAccounts(data[0].split(/\n\s*\n/)); // let accounts = parseWinAccounts(data[0].split(/\n\s*\n/));
data = data.split('#-#-#-#');
let sessions = parseWinSessions(data[0].split(/\n\s*\n/)); let sessions = parseWinSessions(data[0].split(/\n\s*\n/));
let loggedons = parseWinLoggedOn(data[1].split(/\n\s*\n/)); let loggedons = parseWinLoggedOn(data[1].split(/\n\s*\n/));
let users = parseWinUsers(data[2].split(/\n\s*\n/)); let users = parseWinUsers(data[2].split(/\n\s*\n/));

View File

@ -360,7 +360,7 @@ function powerShell(cmd) {
return new Promise((resolve) => { return new Promise((resolve) => {
process.nextTick(() => { process.nextTick(() => {
try { try {
const child = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], { const child = spawn('powershell.exe', ['-NoLogo', '-NoProfile', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], { // added NoProfile
stdio: 'pipe', stdio: 'pipe',
windowsHide: true, windowsHide: true,
maxBuffer: 1024 * 20000, maxBuffer: 1024 * 20000,