windows exec WMIC in try catch

This commit is contained in:
Sebastian Hildebrandt 2018-05-28 23:01:42 +02:00
parent fe9925ec99
commit 2ae03047ce
12 changed files with 791 additions and 681 deletions

View File

@ -100,6 +100,7 @@ Other changes
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 3.41.4 | 2018-05-28 | windows exec WMIC in try catch |
| 3.41.3 | 2018-05-13 | improved SunOS support `getStaticData()`, `getDynamicData()` |
| 3.41.2 | 2018-05-13 | bugfix `system()` and `flags()` Raspberry Pi |
| 3.41.1 | 2018-05-11 | updated docs |

View File

@ -141,23 +141,28 @@ module.exports = function (callback) {
resolve(result);
}
if (_windows) {
exec(util.getWmic() + ' Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value', opts, function (error, stdout) {
if (stdout) {
let lines = stdout.split('\r\n');
let status = util.getValue(lines, 'BatteryStatus', '=').trim();
if (status) {
status = parseInt(status || '2');
result.hasbattery = true;
result.maxcapacity = parseInt(util.getValue(lines, 'DesignCapacity', '=') || 0);
result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', '=') || 0);
result.currentcapacity = parseInt(result.maxcapacity * result.percent / 100);
result.ischarging = (status >= 6 && status <= 9) || (!(status === 3) && !(status === 1) && result.percent < 100);
result.acconnected = result.ischarging;
try {
exec(util.getWmic() + ' Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value', opts, function (error, stdout) {
if (stdout) {
let lines = stdout.split('\r\n');
let status = util.getValue(lines, 'BatteryStatus', '=').trim();
if (status) {
status = parseInt(status || '2');
result.hasbattery = true;
result.maxcapacity = parseInt(util.getValue(lines, 'DesignCapacity', '=') || 0);
result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', '=') || 0);
result.currentcapacity = parseInt(result.maxcapacity * result.percent / 100);
result.ischarging = (status >= 6 && status <= 9) || (!(status === 3) && !(status === 1) && result.percent < 100);
result.acconnected = result.ischarging;
}
}
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
resolve(result);
}
}
});
});

View File

@ -306,70 +306,74 @@ function getCpu() {
resolve(result);
}
if (_windows) {
exec(util.getWmic() + ' cpu get name, description, revision, l2cachesize, l3cachesize, manufacturer, currentclockspeed, maxclockspeed /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n');
let name = util.getValue(lines, 'name', '=') || '';
if (name.indexOf('@') >= 0) {
result.brand = name.split('@')[0].trim();
result.speed = name.split('@')[1].trim();
result.speed = parseFloat(result.speed.replace(/GHz+/g, '').trim()).toFixed(2);
_cpu_speed = result.speed;
} else {
result.brand = name.trim();
result.speed = 0;
}
result = cpuBrandManufacturer(result);
result.revision = util.getValue(lines, 'revision', '=');
result.cache.l1d = 0;
result.cache.l1i = 0;
result.cache.l2 = util.getValue(lines, 'l2cachesize', '=');
result.cache.l3 = util.getValue(lines, 'l3cachesize', '=');
if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; }
if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; }
result.vendor = util.getValue(lines, 'manufacturer', '=');
result.speedmax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100;
result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : '';
if (!result.speed && result.brand.indexOf('AMD') > -1) {
result.speed = getAMDSpeed(result.brand);
}
if (!result.speed) {
result.speed = result.speedmax;
}
let description = util.getValue(lines, 'description', '=').split(' ');
for (let i = 0; i < description.length; i++) {
if (description[i].toLowerCase().startsWith('family') && (i+1) < description.length && description[i+1]) {
result.family = description[i+1];
}
if (description[i].toLowerCase().startsWith('model') && (i+1) < description.length && description[i+1]) {
result.model = description[i+1];
}
if (description[i].toLowerCase().startsWith('stepping') && (i+1) < description.length && description[i+1]) {
result.stepping = description[i+1];
}
}
}
exec(util.getWmic() + ' path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) {
try {
exec(util.getWmic() + ' cpu get name, description, revision, l2cachesize, l3cachesize, manufacturer, currentclockspeed, maxclockspeed /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
// L1 Instructions
if (line[2] === 'L1 Cache' && line[0] === '3') {
result.cache.l1i = parseInt(line[1], 10);
}
// L1 Data
if (line[2] === 'L1 Cache' && line[0] === '4') {
result.cache.l1d = parseInt(line[1], 10);
}
let lines = stdout.split('\r\n');
let name = util.getValue(lines, 'name', '=') || '';
if (name.indexOf('@') >= 0) {
result.brand = name.split('@')[0].trim();
result.speed = name.split('@')[1].trim();
result.speed = parseFloat(result.speed.replace(/GHz+/g, '').trim()).toFixed(2);
_cpu_speed = result.speed;
} else {
result.brand = name.trim();
result.speed = 0;
}
result = cpuBrandManufacturer(result);
result.revision = util.getValue(lines, 'revision', '=');
result.cache.l1d = 0;
result.cache.l1i = 0;
result.cache.l2 = util.getValue(lines, 'l2cachesize', '=');
result.cache.l3 = util.getValue(lines, 'l3cachesize', '=');
if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2, 10) * 1024; }
if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3, 10) * 1024; }
result.vendor = util.getValue(lines, 'manufacturer', '=');
result.speedmax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100;
result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : '';
if (!result.speed && result.brand.indexOf('AMD') > -1) {
result.speed = getAMDSpeed(result.brand);
}
if (!result.speed) {
result.speed = result.speedmax;
}
let description = util.getValue(lines, 'description', '=').split(' ');
for (let i = 0; i < description.length; i++) {
if (description[i].toLowerCase().startsWith('family') && (i+1) < description.length && description[i+1]) {
result.family = description[i+1];
}
});
if (description[i].toLowerCase().startsWith('model') && (i+1) < description.length && description[i+1]) {
result.model = description[i+1];
}
if (description[i].toLowerCase().startsWith('stepping') && (i+1) < description.length && description[i+1]) {
result.stepping = description[i+1];
}
}
}
resolve(result);
exec(util.getWmic() + ' path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
// L1 Instructions
if (line[2] === 'L1 Cache' && line[0] === '3') {
result.cache.l1i = parseInt(line[1], 10);
}
// L1 Data
if (line[2] === 'L1 Cache' && line[0] === '4') {
result.cache.l1d = parseInt(line[1], 10);
}
}
});
}
resolve(result);
});
});
});
} catch (e) {
resolve(result);
}
}
});
});
@ -546,23 +550,28 @@ function cpuTemperature(callback) {
resolve(result);
}
if (_windows) {
exec(util.getWmic() + ' /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature', opts, function (error, stdout) {
if (!error) {
let sum = 0;
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
let value = (parseInt(line) - 2732) / 10;
sum = sum + value;
if (value > result.max) result.max = value;
result.cores.push(value);
});
if (result.cores.length) {
result.main = sum / result.cores.length;
try {
exec(util.getWmic() + ' /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature', opts, function (error, stdout) {
if (!error) {
let sum = 0;
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
let value = (parseInt(line) - 2732) / 10;
sum = sum + value;
if (value > result.max) result.max = value;
result.cores.push(value);
});
if (result.cores.length) {
result.main = sum / result.cores.length;
}
}
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
resolve(result);
}
}
});
});
@ -579,29 +588,34 @@ function cpuFlags(callback) {
process.nextTick(() => {
let result = '';
if (_windows) {
exec('reg query "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0" /v FeatureSet', opts, function (error, stdout) {
if (!error) {
let flag_hex = stdout.split('0x').pop().trim();
let flag_bin_unpadded = parseInt(flag_hex, 16).toString(2);
let flag_bin = '0'.repeat(32 - flag_bin_unpadded.length) + flag_bin_unpadded;
// empty flags are the reserved fields in the CPUID feature bit list
// as found on wikipedia:
// https://en.wikipedia.org/wiki/CPUID
let all_flags = [
'fpu', 'vme', 'de', 'pse', 'tsc', 'msr', 'pae', 'mce', 'cx8', 'apic',
'', 'sep', 'mtrr', 'pge', 'mca', 'cmov', 'pat', 'pse-36', 'psn', 'clfsh',
'', 'ds', 'acpi', 'mmx', 'fxsr', 'sse', 'sse2', 'ss', 'htt', 'tm', 'ia64', 'pbe'
];
for (let f = 0; f < all_flags.length; f++) {
if (flag_bin[f] === '1' && all_flags[f] !== '') {
result += ' ' + all_flags[f];
try {
exec('reg query "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0" /v FeatureSet', opts, function (error, stdout) {
if (!error) {
let flag_hex = stdout.split('0x').pop().trim();
let flag_bin_unpadded = parseInt(flag_hex, 16).toString(2);
let flag_bin = '0'.repeat(32 - flag_bin_unpadded.length) + flag_bin_unpadded;
// empty flags are the reserved fields in the CPUID feature bit list
// as found on wikipedia:
// https://en.wikipedia.org/wiki/CPUID
let all_flags = [
'fpu', 'vme', 'de', 'pse', 'tsc', 'msr', 'pae', 'mce', 'cx8', 'apic',
'', 'sep', 'mtrr', 'pge', 'mca', 'cmov', 'pat', 'pse-36', 'psn', 'clfsh',
'', 'ds', 'acpi', 'mmx', 'fxsr', 'sse', 'sse2', 'ss', 'htt', 'tm', 'ia64', 'pbe'
];
for (let f = 0; f < all_flags.length; f++) {
if (flag_bin[f] === '1' && all_flags[f] !== '') {
result += ' ' + all_flags[f];
}
}
result = result.trim();
}
result = result.trim();
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
resolve(result);
}
}
if (_linux) {
exec('lscpu', function (error, stdout) {
@ -764,37 +778,42 @@ function cpuCache(callback) {
resolve(result);
}
if (_windows) {
exec(util.getWmic() + ' cpu get l2cachesize, l3cachesize /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n');
result.l1d = 0;
result.l1i = 0;
result.l2 = util.getValue(lines, 'l2cachesize', '=');
result.l3 = util.getValue(lines, 'l3cachesize', '=');
if (result.l2) { result.l2 = parseInt(result.l2) * 1024; }
if (result.l3) { result.l3 = parseInt(result.l3) * 1024; }
}
exec(util.getWmic() + ' path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) {
try {
exec(util.getWmic() + ' cpu get l2cachesize, l3cachesize /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
// L1 Instructions
if (line[2] === 'L1 Cache' && line[0] === '3') {
result.l1i = parseInt(line[1], 10);
}
// L1 Data
if (line[2] === 'L1 Cache' && line[0] === '4') {
result.l1d = parseInt(line[1], 10);
}
}
});
let lines = stdout.split('\r\n');
result.l1d = 0;
result.l1i = 0;
result.l2 = util.getValue(lines, 'l2cachesize', '=');
result.l3 = util.getValue(lines, 'l3cachesize', '=');
if (result.l2) { result.l2 = parseInt(result.l2) * 1024; }
if (result.l3) { result.l3 = parseInt(result.l3) * 1024; }
}
if (callback) { callback(result); }
resolve(result);
exec(util.getWmic() + ' path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
// L1 Instructions
if (line[2] === 'L1 Cache' && line[0] === '3') {
result.l1i = parseInt(line[1], 10);
}
// L1 Data
if (line[2] === 'L1 Cache' && line[0] === '4') {
result.l1d = parseInt(line[1], 10);
}
}
});
}
if (callback) { callback(result); }
resolve(result);
});
});
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
}
});
});

View File

@ -78,26 +78,31 @@ function fsSize(callback) {
resolve(data);
}
if (_windows) {
exec(util.getWmic() + ' logicaldisk get Caption,FileSystem,FreeSpace,Size', opts, function (error, stdout) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
data.push({
'fs': line[0],
'type': line[1],
'size': line[3],
'used': parseInt(line[3]) - parseInt(line[2]),
'use': parseFloat((100.0 * (parseInt(line[3]) - parseInt(line[2]))) / parseInt(line[3])),
'mount': line[0]
});
try {
exec(util.getWmic() + ' logicaldisk get Caption,FileSystem,FreeSpace,Size', opts, function (error, stdout) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
data.push({
'fs': line[0],
'type': line[1],
'size': line[3],
'used': parseInt(line[3]) - parseInt(line[2]),
'use': parseFloat((100.0 * (parseInt(line[3]) - parseInt(line[2]))) / parseInt(line[3])),
'mount': line[0]
});
}
});
if (callback) {
callback(data);
}
resolve(data);
});
if (callback) {
callback(data);
}
} catch (e) {
if (callback) { callback(data); }
resolve(data);
});
}
}
});
});
@ -167,7 +172,7 @@ function parseBlk(lines) {
lines.filter(line => line !== '').forEach((line) => {
line = util.decodeEscapeSequence(line);
line = line.replace(/\\/g,'\\\\');
line = line.replace(/\\/g, '\\\\');
let disk = JSON.parse(line);
data.push({
'name': disk.name,
@ -258,36 +263,42 @@ function blockDevices(callback) {
}
if (_windows) {
let drivetypes = ['Unknown', 'NoRoot', 'Removable', 'HDD', 'Network', 'CD/DVD', 'RAM'];
exec(util.getWmic() + ' logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value', opts, function (error, stdout) {
if (!error) {
let devices = stdout.toString().split(/\n\s*\n/);
devices.forEach(function (device) {
let lines = device.split('\r\n');
let drivetype = util.getValue(lines, 'drivetype', '=');
if (drivetype) {
data.push({
name: util.getValue(lines, 'name', '='),
identifier: util.getValue(lines, 'caption', '='),
type: 'disk',
fstype: util.getValue(lines, 'filesystem', '=').toLowerCase(),
mount: util.getValue(lines, 'caption', '='),
size: util.getValue(lines, 'size', '='),
physical: (drivetype >= 0 && drivetype <= 6) ? drivetypes[drivetype] : drivetypes[0],
uuid: util.getValue(lines, 'volumeserialnumber', '='),
label: util.getValue(lines, 'volumename', '='),
model: '',
serial: util.getValue(lines, 'volumeserialnumber', '='),
removable: drivetype === '2',
protocol: ''
});
}
});
}
if (callback) {
callback(data);
}
try {
exec(util.getWmic() + ' logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value', opts, function (error, stdout) {
if (!error) {
let devices = stdout.toString().split(/\n\s*\n/);
devices.forEach(function (device) {
let lines = device.split('\r\n');
let drivetype = util.getValue(lines, 'drivetype', '=');
if (drivetype) {
data.push({
name: util.getValue(lines, 'name', '='),
identifier: util.getValue(lines, 'caption', '='),
type: 'disk',
fstype: util.getValue(lines, 'filesystem', '=').toLowerCase(),
mount: util.getValue(lines, 'caption', '='),
size: util.getValue(lines, 'size', '='),
physical: (drivetype >= 0 && drivetype <= 6) ? drivetypes[drivetype] : drivetypes[0],
uuid: util.getValue(lines, 'volumeserialnumber', '='),
label: util.getValue(lines, 'volumename', '='),
model: '',
serial: util.getValue(lines, 'volumeserialnumber', '='),
removable: drivetype === '2',
protocol: ''
});
}
});
}
if (callback) {
callback(data);
}
resolve(data);
});
} catch (e) {
if (callback) { callback(data); }
resolve(data);
});
}
}
});
});
@ -735,38 +746,42 @@ function diskLayout(callback) {
});
}
if (_windows) {
exec(util.getWmic() + ' diskdrive get /value', {encoding: 'utf8', windowsHide: true}, function (error, stdout) {
if (!error) {
let devices = stdout.toString().split(/\n\s*\n/);
devices.forEach(function (device) {
let lines = device.split('\r\n');
const size = util.getValue(lines, 'Size', '=').trim();
if (size) {
result.push({
type: device.indexOf('SSD') > -1 ? 'SSD' : 'HD', // not really correct(!) ... maybe this one is better: MSFT_PhysicalDisk - Media Type??
name: util.getValue(lines, 'Caption', '='),
vendor: util.getValue(lines, 'Manufacturer', '='),
size: parseInt(size),
bytesPerSector: parseInt(util.getValue(lines, 'BytesPerSector', '=')),
totalCylinders: parseInt(util.getValue(lines, 'TotalCylinders', '=')),
totalHeads: parseInt(util.getValue(lines, 'TotalHeads', '=')),
totalSectors: parseInt(util.getValue(lines, 'TotalSectors', '=')),
totalTracks: parseInt(util.getValue(lines, 'TotalTracks', '=')),
tracksPerCylinder: parseInt(util.getValue(lines, 'TracksPerCylinder', '=')),
sectorsPerTrack: parseInt(util.getValue(lines, 'SectorsPerTrack', '=')),
firmwareRevision: util.getValue(lines, 'FirmwareRevision', '=').trim(),
serialNum: util.getValue(lines, 'SerialNumber', '=').trim(),
interfaceType: util.getValue(lines, 'InterfaceType', '=').trim()
});
}
});
}
if (callback) {
callback(result);
}
try {
exec(util.getWmic() + ' diskdrive get /value', { encoding: 'utf8', windowsHide: true }, function (error, stdout) {
if (!error) {
let devices = stdout.toString().split(/\n\s*\n/);
devices.forEach(function (device) {
let lines = device.split('\r\n');
const size = util.getValue(lines, 'Size', '=').trim();
if (size) {
result.push({
type: device.indexOf('SSD') > -1 ? 'SSD' : 'HD', // not really correct(!) ... maybe this one is better: MSFT_PhysicalDisk - Media Type??
name: util.getValue(lines, 'Caption', '='),
vendor: util.getValue(lines, 'Manufacturer', '='),
size: parseInt(size),
bytesPerSector: parseInt(util.getValue(lines, 'BytesPerSector', '=')),
totalCylinders: parseInt(util.getValue(lines, 'TotalCylinders', '=')),
totalHeads: parseInt(util.getValue(lines, 'TotalHeads', '=')),
totalSectors: parseInt(util.getValue(lines, 'TotalSectors', '=')),
totalTracks: parseInt(util.getValue(lines, 'TotalTracks', '=')),
tracksPerCylinder: parseInt(util.getValue(lines, 'TracksPerCylinder', '=')),
sectorsPerTrack: parseInt(util.getValue(lines, 'SectorsPerTrack', '=')),
firmwareRevision: util.getValue(lines, 'FirmwareRevision', '=').trim(),
serialNum: util.getValue(lines, 'SerialNumber', '=').trim(),
interfaceType: util.getValue(lines, 'InterfaceType', '=').trim()
});
}
});
}
if (callback) {
callback(result);
}
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
}
}
});
});

View File

@ -338,33 +338,38 @@ function graphics(callback) {
}
if (_windows) {
// https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/
exec(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', opts, function (error, stdout) {
if (!error) {
let csections = stdout.split(/\n\s*\n/);
result.controllers = parseLinesWindowsControllers(csections);
exec(util.getWmic() + ' path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value', opts, function (error, stdout) {
let dsections = stdout.split(/\n\s*\n/);
if (!error) {
result.displays = parseLinesWindowsDisplays(dsections);
if (result.controllers.length === 1 && result.displays.length === 1) {
if (_resolutionx && !result.displays[0].resolutionx) {
result.displays[0].resolutionx = _resolutionx;
}
if (_resolutiony && !result.displays[0].resolutiony) {
result.displays[0].resolutiony = _resolutiony;
}
if (_pixeldepth) {
result.displays[0].pixeldepth = _pixeldepth;
try {
exec(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', opts, function (error, stdout) {
if (!error) {
let csections = stdout.split(/\n\s*\n/);
result.controllers = parseLinesWindowsControllers(csections);
exec(util.getWmic() + ' path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value', opts, function (error, stdout) {
let dsections = stdout.split(/\n\s*\n/);
if (!error) {
result.displays = parseLinesWindowsDisplays(dsections);
if (result.controllers.length === 1 && result.displays.length === 1) {
if (_resolutionx && !result.displays[0].resolutionx) {
result.displays[0].resolutionx = _resolutionx;
}
if (_resolutiony && !result.displays[0].resolutiony) {
result.displays[0].resolutiony = _resolutiony;
}
if (_pixeldepth) {
result.displays[0].pixeldepth = _pixeldepth;
}
}
}
}
if (callback) {
callback(result);
}
resolve(result);
});
}
});
if (callback) {
callback(result);
}
resolve(result);
});
}
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
}
});
});

View File

@ -157,23 +157,28 @@ function inetLatency(host, callback) {
});
}
if (_windows) {
exec('ping ' + host + ' -n 1', opts, function (error, stdout) {
let result = -1;
if (!error) {
let lines = stdout.toString().split('\r\n');
lines.shift();
lines.forEach(function (line) {
if (line.toLowerCase().startsWith(' min')) {
let l = line.replace(/ +/g, ' ').split(' ');
if (l.length > 8) {
result = parseFloat(l[9]);
let result = -1;
try {
exec('ping ' + host + ' -n 1', opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');
lines.shift();
lines.forEach(function (line) {
if (line.toLowerCase().startsWith(' min')) {
let l = line.replace(/ +/g, ' ').split(' ');
if (l.length > 8) {
result = parseFloat(l[9]);
}
}
}
});
}
});
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
}
}
});
});

View File

@ -199,24 +199,29 @@ function mem(callback) {
if (_windows) {
let swaptotal = 0;
let swapused = 0;
exec(util.getWmic() + ' pagefile get AllocatedBaseSize, CurrentUsage', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
swaptotal = swaptotal + parseInt(line[0], 10);
swapused = swapused + parseInt(line[1], 10);
}
});
}
result.swaptotal = swaptotal * 1024 * 1024;
result.swapused = swapused * 1024 * 1024;
result.swapfree = result.swaptotal - result.swapused;
try {
exec(util.getWmic() + ' pagefile get AllocatedBaseSize, CurrentUsage', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) {
if (line !== '') {
line = line.trim().split(/\s\s+/);
swaptotal = swaptotal + parseInt(line[0], 10);
swapused = swapused + parseInt(line[1], 10);
}
});
}
result.swaptotal = swaptotal * 1024 * 1024;
result.swapused = swapused * 1024 * 1024;
result.swapfree = result.swaptotal - result.swapused;
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
}
}
});
});
@ -228,7 +233,7 @@ function memLayout(callback) {
function getManufacturer(manId) {
if (OSX_RAM_manufacturers.hasOwnProperty(manId)) {
return(OSX_RAM_manufacturers[manId]);
return (OSX_RAM_manufacturers[manId]);
}
return manId;
}
@ -247,7 +252,7 @@ function memLayout(callback) {
let lines = device.split('\n');
if (parseInt(util.getValue(lines, 'Size'), 10) > 0) {
result.push({
size: parseInt(util.getValue(lines, 'Size'), 10)*1024*1024,
size: parseInt(util.getValue(lines, 'Size'), 10) * 1024 * 1024,
bank: util.getValue(lines, 'Bank Locator'),
type: util.getValue(lines, 'Type:'),
clockSpeed: (util.getValue(lines, 'Configured Clock Speed:') ? parseInt(util.getValue(lines, 'Configured Clock Speed:'), 10) : (util.getValue(lines, 'Speed:') ? parseInt(util.getValue(lines, 'Speed:'), 10) : -1)),
@ -332,30 +337,35 @@ function memLayout(callback) {
const memoryTypes = 'Unknown|Other|DRAM|Synchronous DRAM|Cache DRAM|EDO|EDRAM|VRAM|SRAM|RAM|ROM|FLASH|EEPROM|FEPROM|EPROM|CDRAM|3DRAM|SDRAM|SGRAM|RDRAM|DDR|DDR2|DDR2 FB-DIMM|Reserved|DDR3|FBD2|DDR4|LPDDR|LPDDR2|LPDDR3|LPDDR4'.split('|');
const FormFactors = 'Unknown|Other|SIP|DIP|ZIP|SOJ|Proprietary|SIMM|DIMM|TSOP|PGA|RIMM|SODIMM|SRIMM|SMD|SSMP|QFP|TQFP|SOIC|LCC|PLCC|BGA|FPBGA|LGA'.split('|');
exec(util.getWmic() + ' memorychip get BankLabel, Capacity, ConfiguredClockSpeed, ConfiguredVoltage, MaxVoltage, MinVoltage, DataWidth, FormFactor, Manufacturer, MemoryType, PartNumber, SerialNumber, Speed, Tag /value', opts, function (error, stdout) {
if (!error) {
let devices = stdout.toString().split('BankL');
devices.shift();
devices.forEach(function (device) {
let lines = device.split('\r\n');
result.push({
size: parseInt(util.getValue(lines, 'Capacity', '='), 10),
bank: util.getValue(lines, 'abel', '='), // BankLabel
type: memoryTypes[parseInt(util.getValue(lines, 'MemoryType', '='), 10)],
clockSpeed: parseInt(util.getValue(lines, 'ConfiguredClockSpeed', '='), 10),
formFactor: FormFactors[parseInt(util.getValue(lines, 'FormFactor', '='), 10)],
manufacturer: util.getValue(lines, 'Manufacturer', '='),
partNum: util.getValue(lines, 'PartNumber', '='),
serialNum: util.getValue(lines, 'SerialNumber', '='),
voltageConfigured: parseInt(util.getValue(lines, 'ConfiguredVoltage', '='), 10) / 1000.0,
voltageMin: parseInt(util.getValue(lines, 'MinVoltage', '='), 10) / 1000.0,
voltageMax: parseInt(util.getValue(lines, 'MaxVoltage', '='), 10) / 1000.0,
try {
exec(util.getWmic() + ' memorychip get BankLabel, Capacity, ConfiguredClockSpeed, ConfiguredVoltage, MaxVoltage, MinVoltage, DataWidth, FormFactor, Manufacturer, MemoryType, PartNumber, SerialNumber, Speed, Tag /value', opts, function (error, stdout) {
if (!error) {
let devices = stdout.toString().split('BankL');
devices.shift();
devices.forEach(function (device) {
let lines = device.split('\r\n');
result.push({
size: parseInt(util.getValue(lines, 'Capacity', '='), 10),
bank: util.getValue(lines, 'abel', '='), // BankLabel
type: memoryTypes[parseInt(util.getValue(lines, 'MemoryType', '='), 10)],
clockSpeed: parseInt(util.getValue(lines, 'ConfiguredClockSpeed', '='), 10),
formFactor: FormFactors[parseInt(util.getValue(lines, 'FormFactor', '='), 10)],
manufacturer: util.getValue(lines, 'Manufacturer', '='),
partNum: util.getValue(lines, 'PartNumber', '='),
serialNum: util.getValue(lines, 'SerialNumber', '='),
voltageConfigured: parseInt(util.getValue(lines, 'ConfiguredVoltage', '='), 10) / 1000.0,
voltageMin: parseInt(util.getValue(lines, 'MinVoltage', '='), 10) / 1000.0,
voltageMax: parseInt(util.getValue(lines, 'MaxVoltage', '='), 10) / 1000.0,
});
});
});
}
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
}
}
});
});

View File

@ -366,57 +366,62 @@ function networkStats(iface, callback) {
let perfData = [];
let nics = [];
cmd = util.getWmic() + ' nic get MACAddress, name, NetEnabled /value';
exec(cmd, opts, function (error, stdout) {
if (!error) {
const nsections = stdout.split(/\n\s*\n/);
nics = parseLinesWindowsNics(nsections);
// Performance Data
cmd = util.getWmic() + ' path Win32_PerfRawData_Tcpip_NetworkInterface Get name,BytesReceivedPersec,BytesSentPersec,BytesTotalPersec /value';
exec(cmd, opts, function (error, stdout) {
if (!error) {
const psections = stdout.split(/\n\s*\n/);
perfData = parseLinesWindowsPerfData(psections);
}
// Network Interfaces
networkInterfaces().then(interfaces => {
// get mac from 'interfaces' by interfacename
let mac = '';
interfaces.forEach(detail => {
if (detail.iface === iface) {
mac = detail.mac;
}
});
// get name from 'nics' (by macadress)
let name = '';
nics.forEach(detail => {
if (detail.mac === mac) {
name = detail.name;
operstate = (detail.netEnabled ? 'up' : 'down');
}
});
// get bytes sent, received from perfData by name
rx = 0;
tx = 0;
perfData.forEach(detail => {
if (detail.name === name) {
rx = detail.rx;
tx = detail.tx;
}
});
if (rx && tx) {
result = calcNetworkSpeed(iface, parseInt(rx), parseInt(tx), operstate);
try {
exec(cmd, opts, function (error, stdout) {
if (!error) {
const nsections = stdout.split(/\n\s*\n/);
nics = parseLinesWindowsNics(nsections);
// Performance Data
cmd = util.getWmic() + ' path Win32_PerfRawData_Tcpip_NetworkInterface Get name,BytesReceivedPersec,BytesSentPersec,BytesTotalPersec /value';
exec(cmd, opts, function (error, stdout) {
if (!error) {
const psections = stdout.split(/\n\s*\n/);
perfData = parseLinesWindowsPerfData(psections);
}
if (callback) { callback(result); }
resolve(result);
// Network Interfaces
networkInterfaces().then(interfaces => {
// get mac from 'interfaces' by interfacename
let mac = '';
interfaces.forEach(detail => {
if (detail.iface === iface) {
mac = detail.mac;
}
});
// get name from 'nics' (by macadress)
let name = '';
nics.forEach(detail => {
if (detail.mac === mac) {
name = detail.name;
operstate = (detail.netEnabled ? 'up' : 'down');
}
});
// get bytes sent, received from perfData by name
rx = 0;
tx = 0;
perfData.forEach(detail => {
if (detail.name === name) {
rx = detail.rx;
tx = detail.tx;
}
});
if (rx && tx) {
result = calcNetworkSpeed(iface, parseInt(rx), parseInt(tx), operstate);
}
if (callback) { callback(result); }
resolve(result);
});
});
});
}
});
}
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
}
} else {
result.rx = _network[iface].rx;
@ -582,59 +587,64 @@ function networkConnections(callback) {
}
if (_windows) {
let cmd = 'netstat -na';
exec(cmd, opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');
lines.forEach(function (line) {
line = line.trim().replace(/ +/g, ' ').split(' ');
if (line.length >= 4) {
let localip = line[1];
let localport = '';
let localaddress = line[1].split(':');
if (localaddress.length > 1) {
localport = localaddress[localaddress.length - 1];
localaddress.pop();
localip = localaddress.join(':');
}
let peerip = line[2];
let peerport = '';
let peeraddress = line[2].split(':');
if (peeraddress.length > 1) {
peerport = peeraddress[peeraddress.length - 1];
peeraddress.pop();
peerip = peeraddress.join(':');
}
let connstate = line[3];
if (connstate === 'HERGESTELLT') connstate = 'ESTABLISHED';
if (connstate.startsWith('ABH')) connstate = 'LISTEN';
if (connstate === 'SCHLIESSEN_WARTEN') connstate = 'CLOSE_WAIT';
if (connstate === 'WARTEND') connstate = 'TIME_WAIT';
if (connstate === 'SYN_GESENDET') connstate = 'SYN_SENT';
if (connstate === 'LISTENING') connstate = 'LISTEN';
if (connstate === 'SYN_RECEIVED') connstate = 'SYN_RECV';
if (connstate === 'FIN_WAIT_1') connstate = 'FIN_WAIT1';
if (connstate === 'FIN_WAIT_2') connstate = 'FIN_WAIT2';
if (connstate) {
result.push({
protocol: line[0].toLowerCase(),
localaddress: localip,
localport: localport,
peeraddress: peerip,
peerport: peerport,
state: connstate
});
try {
exec(cmd, opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');
lines.forEach(function (line) {
line = line.trim().replace(/ +/g, ' ').split(' ');
if (line.length >= 4) {
let localip = line[1];
let localport = '';
let localaddress = line[1].split(':');
if (localaddress.length > 1) {
localport = localaddress[localaddress.length - 1];
localaddress.pop();
localip = localaddress.join(':');
}
let peerip = line[2];
let peerport = '';
let peeraddress = line[2].split(':');
if (peeraddress.length > 1) {
peerport = peeraddress[peeraddress.length - 1];
peeraddress.pop();
peerip = peeraddress.join(':');
}
let connstate = line[3];
if (connstate === 'HERGESTELLT') connstate = 'ESTABLISHED';
if (connstate.startsWith('ABH')) connstate = 'LISTEN';
if (connstate === 'SCHLIESSEN_WARTEN') connstate = 'CLOSE_WAIT';
if (connstate === 'WARTEND') connstate = 'TIME_WAIT';
if (connstate === 'SYN_GESENDET') connstate = 'SYN_SENT';
if (connstate === 'LISTENING') connstate = 'LISTEN';
if (connstate === 'SYN_RECEIVED') connstate = 'SYN_RECV';
if (connstate === 'FIN_WAIT_1') connstate = 'FIN_WAIT1';
if (connstate === 'FIN_WAIT_2') connstate = 'FIN_WAIT2';
if (connstate) {
result.push({
protocol: line[0].toLowerCase(),
localaddress: localip,
localport: localport,
peeraddress: peerip,
peerport: peerport,
state: connstate
});
}
}
});
if (callback) {
callback(result);
}
});
if (callback) {
callback(result);
resolve(result);
}
resolve(result);
}
});
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
}
});
});

View File

@ -244,13 +244,18 @@ function osInfo(callback) {
if (_windows) {
result.logofile = getLogoFile();
result.release = result.kernel;
exec(util.getWmic() + ' os get Caption', opts, function (error, stdout) {
result.distro = result.codename = stdout.slice(stdout.indexOf('\r\n') + 2).trim();
if (callback) {
callback(result);
}
resolve(result);
});
try {
exec(util.getWmic() + ' os get Caption', opts, function (error, stdout) {
result.distro = result.codename = stdout.slice(stdout.indexOf('\r\n') + 2).trim();
if (callback) {
callback(result);
}
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
}
});
});
@ -292,95 +297,100 @@ function versions(callback) {
};
})();
exec('npm -v', function (error, stdout) {
if (!error) {
result.npm = stdout.toString().split('\n')[0];
}
functionProcessed();
});
exec('pm2 -v', function (error, stdout) {
if (!error) {
result.pm2 = stdout.toString().split('\n')[0].trim();
}
functionProcessed();
});
exec('yarn --version', function (error, stdout) {
if (!error) {
result.yarn = stdout.toString().split('\n')[0];
}
functionProcessed();
});
exec('gulp --version', function (error, stdout) {
if (!error) {
result.gulp = stdout.toString().split('\n')[0] || '';
result.gulp = (result.gulp.toLowerCase().split('version')[1] || '').trim();
}
functionProcessed();
});
exec('tsc --version', function (error, stdout) {
if (!error) {
result.tsc = stdout.toString().split('\n')[0] || '';
result.tsc = (result.tsc.toLowerCase().split('version')[1] || '').trim();
}
functionProcessed();
});
exec('grunt --version', function (error, stdout) {
if (!error) {
result.grunt = stdout.toString().split('\n')[0] || '';
result.grunt = (result.grunt.toLowerCase().split('cli v')[1] || '').trim();
}
functionProcessed();
});
exec('git --version', function (error, stdout) {
if (!error) {
result.git = stdout.toString().split('\n')[0] || '';
result.git = (result.git.toLowerCase().split('version')[1] || '').trim();
result.git = (result.git.split(' ')[0] || '').trim();
}
functionProcessed();
});
exec('nginx -v', function (error, stdout) {
if (!error) {
result.nginx = stdout.toString().split('\n')[0] || '';
result.nginx = (result.nginx.toLowerCase().split('/')[1] || '').trim();
}
functionProcessed();
});
exec('mysql -V', function (error, stdout) {
if (!error) {
result.mysql = stdout.toString().split('\n')[0] || '';
result.mysql = (result.mysql.toLowerCase().split(',')[0] || '').trim();
const parts = result.mysql.split(' ');
result.mysql = (parts[parts.length - 1] || '').trim();
}
functionProcessed();
});
exec('php -v', function (error, stdout) {
if (!error) {
result.php = stdout.toString().split('\n')[0] || '';
let parts = result.php.split('(');
if (parts[0].indexOf('-')) {
parts = parts[0].split('-');
try {
exec('npm -v', function (error, stdout) {
if (!error) {
result.npm = stdout.toString().split('\n')[0];
}
result.php = parts[0].replace(/[^0-9.]/g, '');
}
functionProcessed();
});
exec('redis-server --version', function (error, stdout) {
if (!error) {
result.redis = stdout.toString().split('\n')[0] || '';
const parts = result.redis.split(' ');
result.redis = util.getValue(parts, 'v', '=', true);
}
functionProcessed();
});
exec('mongod --version', function (error, stdout) {
if (!error) {
result.mongodb = stdout.toString().split('\n')[0] || '';
result.mongodb = (result.mongodb.toLowerCase().split(',')[0] || '').replace(/[^0-9.]/g, '');
}
functionProcessed();
});
functionProcessed();
});
exec('pm2 -v', function (error, stdout) {
if (!error) {
result.pm2 = stdout.toString().split('\n')[0].trim();
}
functionProcessed();
});
exec('yarn --version', function (error, stdout) {
if (!error) {
result.yarn = stdout.toString().split('\n')[0];
}
functionProcessed();
});
exec('gulp --version', function (error, stdout) {
if (!error) {
result.gulp = stdout.toString().split('\n')[0] || '';
result.gulp = (result.gulp.toLowerCase().split('version')[1] || '').trim();
}
functionProcessed();
});
exec('tsc --version', function (error, stdout) {
if (!error) {
result.tsc = stdout.toString().split('\n')[0] || '';
result.tsc = (result.tsc.toLowerCase().split('version')[1] || '').trim();
}
functionProcessed();
});
exec('grunt --version', function (error, stdout) {
if (!error) {
result.grunt = stdout.toString().split('\n')[0] || '';
result.grunt = (result.grunt.toLowerCase().split('cli v')[1] || '').trim();
}
functionProcessed();
});
exec('git --version', function (error, stdout) {
if (!error) {
result.git = stdout.toString().split('\n')[0] || '';
result.git = (result.git.toLowerCase().split('version')[1] || '').trim();
result.git = (result.git.split(' ')[0] || '').trim();
}
functionProcessed();
});
exec('nginx -v', function (error, stdout) {
if (!error) {
result.nginx = stdout.toString().split('\n')[0] || '';
result.nginx = (result.nginx.toLowerCase().split('/')[1] || '').trim();
}
functionProcessed();
});
exec('mysql -V', function (error, stdout) {
if (!error) {
result.mysql = stdout.toString().split('\n')[0] || '';
result.mysql = (result.mysql.toLowerCase().split(',')[0] || '').trim();
const parts = result.mysql.split(' ');
result.mysql = (parts[parts.length - 1] || '').trim();
}
functionProcessed();
});
exec('php -v', function (error, stdout) {
if (!error) {
result.php = stdout.toString().split('\n')[0] || '';
let parts = result.php.split('(');
if (parts[0].indexOf('-')) {
parts = parts[0].split('-');
}
result.php = parts[0].replace(/[^0-9.]/g, '');
}
functionProcessed();
});
exec('redis-server --version', function (error, stdout) {
if (!error) {
result.redis = stdout.toString().split('\n')[0] || '';
const parts = result.redis.split(' ');
result.redis = util.getValue(parts, 'v', '=', true);
}
functionProcessed();
});
exec('mongod --version', function (error, stdout) {
if (!error) {
result.mongodb = stdout.toString().split('\n')[0] || '';
result.mongodb = (result.mongodb.toLowerCase().split(',')[0] || '').replace(/[^0-9.]/g, '');
}
functionProcessed();
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
});
});
}

View File

@ -140,52 +140,57 @@ function services(srv, callback) {
}
}
if (_windows) {
exec(util.getWmic() + ' service get /value', { maxBuffer: 1024 * 1000, windowsHide: true }, function (error, stdout) {
if (!error) {
let serviceSections = stdout.split(/\n\s*\n/);
for (let i = 0; i < serviceSections.length; i++) {
if (serviceSections[i].trim() !== '') {
let lines = serviceSections[i].trim().split('\r\n');
let srv = util.getValue(lines, 'Name', '=', true).toLowerCase();
let started = util.getValue(lines, 'Started', '=', true);
if (srvs.indexOf(srv) >= 0) {
data.push({
'name': srv,
'running': (started === 'TRUE'),
'pcpu': 0,
'pmem': 0
});
dataSrv.push(srv);
try {
exec(util.getWmic() + ' service get /value', { maxBuffer: 1024 * 1000, windowsHide: true }, function (error, stdout) {
if (!error) {
let serviceSections = stdout.split(/\n\s*\n/);
for (let i = 0; i < serviceSections.length; i++) {
if (serviceSections[i].trim() !== '') {
let lines = serviceSections[i].trim().split('\r\n');
let srv = util.getValue(lines, 'Name', '=', true).toLowerCase();
let started = util.getValue(lines, 'Started', '=', true);
if (srvs.indexOf(srv) >= 0) {
data.push({
'name': srv,
'running': (started === 'TRUE'),
'pcpu': 0,
'pmem': 0
});
dataSrv.push(srv);
}
}
}
let srvsMissing = srvs.filter(function (e) {
return dataSrv.indexOf(e) === -1;
});
srvsMissing.forEach(function (srv) {
data.push({
'name': srv,
'running': false,
'pcpu': 0,
'pmem': 0
});
});
if (callback) { callback(data); }
resolve(data);
} else {
srvs.forEach(function (srv) {
data.push({
'name': srv,
'running': false,
'pcpu': 0,
'pmem': 0
});
});
if (callback) { callback(data); }
resolve(data);
}
let srvsMissing = srvs.filter(function (e) {
return dataSrv.indexOf(e) === -1;
});
srvsMissing.forEach(function (srv) {
data.push({
'name': srv,
'running': false,
'pcpu': 0,
'pmem': 0
});
});
if (callback) { callback(data); }
resolve(data);
} else {
srvs.forEach(function (srv) {
data.push({
'name': srv,
'running': false,
'pcpu': 0,
'pmem': 0
});
});
if (callback) { callback(data); }
resolve(data);
}
});
});
} catch (e) {
if (callback) { callback(data); }
resolve(data);
}
}
} else {
if (callback) { callback({}); }
@ -582,90 +587,95 @@ function processes(callback) {
});
}
if (_windows) {
exec(util.getWmic() + ' process get /value', { maxBuffer: 1024 * 1000, windowsHide: true }, function (error, stdout) {
if (!error) {
let processSections = stdout.split(/\n\s*\n/);
let procs = [];
let procStats = [];
let list_new = {};
let allcpuu = 0;
let allcpus = 0;
for (let i = 0; i < processSections.length; i++) {
if (processSections[i].trim() !== '') {
let lines = processSections[i].trim().split('\r\n');
let pid = parseInt(util.getValue(lines, 'ProcessId', '=', true), 10);
let statusValue = util.getValue(lines, 'ExecutionState', '=');
let name = util.getValue(lines, 'Caption', '=', true);
let commandLine = util.getValue(lines, 'CommandLine', '=', true);
let utime = parseInt(util.getValue(lines, 'UserModeTime', '=', true), 10);
let stime = parseInt(util.getValue(lines, 'KernelModeTime', '=', true), 10);
let mem = parseInt(util.getValue(lines, 'WorkingSetSize', '=', true), 10);
allcpuu = allcpuu + utime;
allcpus = allcpus + stime;
result.all++;
if (!statusValue) { result.unknown++; }
if (statusValue === '3') { result.running++; }
if (statusValue === '4' || statusValue === '5') { result.blocked++; }
procStats.push({
pid: pid,
utime: utime,
stime: stime,
pcpu: 0,
pcpuu: 0,
pcpus: 0,
});
procs.push({
pid: pid,
name: name,
pcpu: 0,
pcpuu: 0,
pcpus: 0,
pmem: mem / os.totalmem() * 100,
priority: parseInt(util.getValue(lines, 'Priority', '=', true), 10),
mem_vsz: parseInt(util.getValue(lines, 'PageFileUsage', '=', true), 10),
mem_rss: Math.floor(parseInt(util.getValue(lines, 'WorkingSetSize', '=', true), 10) / 1024),
nice: 0,
started: parseTimeWin(util.getValue(lines, 'CreationDate', '=', true)),
state: (!statusValue ? _winStatusValues[0] : _winStatusValues[statusValue]),
tty: '',
user: '',
command: commandLine || name
});
try {
exec(util.getWmic() + ' process get /value', { maxBuffer: 1024 * 1000, windowsHide: true }, function (error, stdout) {
if (!error) {
let processSections = stdout.split(/\n\s*\n/);
let procs = [];
let procStats = [];
let list_new = {};
let allcpuu = 0;
let allcpus = 0;
for (let i = 0; i < processSections.length; i++) {
if (processSections[i].trim() !== '') {
let lines = processSections[i].trim().split('\r\n');
let pid = parseInt(util.getValue(lines, 'ProcessId', '=', true), 10);
let statusValue = util.getValue(lines, 'ExecutionState', '=');
let name = util.getValue(lines, 'Caption', '=', true);
let commandLine = util.getValue(lines, 'CommandLine', '=', true);
let utime = parseInt(util.getValue(lines, 'UserModeTime', '=', true), 10);
let stime = parseInt(util.getValue(lines, 'KernelModeTime', '=', true), 10);
let mem = parseInt(util.getValue(lines, 'WorkingSetSize', '=', true), 10);
allcpuu = allcpuu + utime;
allcpus = allcpus + stime;
result.all++;
if (!statusValue) { result.unknown++; }
if (statusValue === '3') { result.running++; }
if (statusValue === '4' || statusValue === '5') { result.blocked++; }
procStats.push({
pid: pid,
utime: utime,
stime: stime,
pcpu: 0,
pcpuu: 0,
pcpus: 0,
});
procs.push({
pid: pid,
name: name,
pcpu: 0,
pcpuu: 0,
pcpus: 0,
pmem: mem / os.totalmem() * 100,
priority: parseInt(util.getValue(lines, 'Priority', '=', true), 10),
mem_vsz: parseInt(util.getValue(lines, 'PageFileUsage', '=', true), 10),
mem_rss: Math.floor(parseInt(util.getValue(lines, 'WorkingSetSize', '=', true), 10) / 1024),
nice: 0,
started: parseTimeWin(util.getValue(lines, 'CreationDate', '=', true)),
state: (!statusValue ? _winStatusValues[0] : _winStatusValues[statusValue]),
tty: '',
user: '',
command: commandLine || name
});
}
}
}
result.sleeping = result.all - result.running - result.blocked - result.unknown;
result.list = procs;
for (let i = 0; i < procStats.length; i++) {
let resultProcess = calcProcPidStat(procStats[i], allcpuu + allcpus);
// store pcpu in outer array
let listPos = result.list.map(function (e) { return e.pid; }).indexOf(resultProcess.pid);
if (listPos >= 0) {
result.list[listPos].pcpu = resultProcess.pcpuu + resultProcess.pcpus;
result.list[listPos].pcpuu = resultProcess.pcpuu;
result.list[listPos].pcpus = resultProcess.pcpus;
result.sleeping = result.all - result.running - result.blocked - result.unknown;
result.list = procs;
for (let i = 0; i < procStats.length; i++) {
let resultProcess = calcProcPidStat(procStats[i], allcpuu + allcpus);
// store pcpu in outer array
let listPos = result.list.map(function (e) { return e.pid; }).indexOf(resultProcess.pid);
if (listPos >= 0) {
result.list[listPos].pcpu = resultProcess.pcpuu + resultProcess.pcpus;
result.list[listPos].pcpuu = resultProcess.pcpuu;
result.list[listPos].pcpus = resultProcess.pcpus;
}
// save new values
list_new[resultProcess.pid] = {
pcpuu: resultProcess.pcpuu,
pcpus: resultProcess.pcpus,
utime: resultProcess.utime,
stime: resultProcess.stime
};
}
// save new values
list_new[resultProcess.pid] = {
pcpuu: resultProcess.pcpuu,
pcpus: resultProcess.pcpus,
utime: resultProcess.utime,
stime: resultProcess.stime
};
// store old values
_process_cpu.all = allcpuu + allcpus;
_process_cpu.list = list_new;
_process_cpu.ms = Date.now() - _process_cpu.ms;
_process_cpu.result = result;
}
// store old values
_process_cpu.all = allcpuu + allcpus;
_process_cpu.list = list_new;
_process_cpu.ms = Date.now() - _process_cpu.ms;
_process_cpu.result = result;
}
if (callback) {
callback(result);
}
resolve(result);
});
if (callback) {
callback(result);
}
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
}
} else {
if (callback) { callback(_process_cpu.result); }

View File

@ -188,27 +188,32 @@ function system(callback) {
resolve(result);
}
if (_windows) {
exec(util.getWmic() + ' csproduct get /value', opts, function (error, stdout) {
if (!error) {
// let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
let lines = stdout.split('\r\n');
result.manufacturer = util.getValue(lines, 'vendor', '=');
result.model = util.getValue(lines, 'name', '=');
result.version = util.getValue(lines, 'version', '=');
result.serial = util.getValue(lines, 'identifyingnumber', '=');
result.uuid = util.getValue(lines, 'uuid', '=');
exec(util.getWmic() + ' /namespace:\\\\root\\wmi path MS_SystemInformation get /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n');
result.sku = util.getValue(lines, 'systemsku', '=');
}
if (callback) { callback(result); }
resolve(result);
});
}
try {
exec(util.getWmic() + ' csproduct get /value', opts, function (error, stdout) {
if (!error) {
// let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
let lines = stdout.split('\r\n');
result.manufacturer = util.getValue(lines, 'vendor', '=');
result.model = util.getValue(lines, 'name', '=');
result.version = util.getValue(lines, 'version', '=');
result.serial = util.getValue(lines, 'identifyingnumber', '=');
result.uuid = util.getValue(lines, 'uuid', '=');
exec(util.getWmic() + ' /namespace:\\\\root\\wmi path MS_SystemInformation get /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n');
result.sku = util.getValue(lines, 'systemsku', '=');
}
if (callback) { callback(result); }
resolve(result);
});
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
resolve(result);
}
}
});
});
@ -261,32 +266,37 @@ function bios(callback) {
}
if (_windows) {
// TODO: check BIOS windows
exec(util.getWmic() + ' bios get /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');
const description = util.getValue(lines, 'description', '=');
if (description.indexOf(' Version ') !== -1) {
// ... Phoenix ROM BIOS PLUS Version 1.10 A04
result.vendor = description.split(' Version ')[0].trim();
result.version = description.split(' Version ')[1].trim();
} else if (description.indexOf(' Ver: ') !== -1) {
// ... BIOS Date: 06/27/16 17:50:16 Ver: 1.4.5
result.vendor = util.getValue(lines, 'manufacturer', '=');
result.version = description.split(' Ver: ')[1].trim();
} else {
result.vendor = util.getValue(lines, 'manufacturer', '=');
result.version = util.getValue(lines, 'version', '=');
try {
exec(util.getWmic() + ' bios get /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');
const description = util.getValue(lines, 'description', '=');
if (description.indexOf(' Version ') !== -1) {
// ... Phoenix ROM BIOS PLUS Version 1.10 A04
result.vendor = description.split(' Version ')[0].trim();
result.version = description.split(' Version ')[1].trim();
} else if (description.indexOf(' Ver: ') !== -1) {
// ... BIOS Date: 06/27/16 17:50:16 Ver: 1.4.5
result.vendor = util.getValue(lines, 'manufacturer', '=');
result.version = description.split(' Ver: ')[1].trim();
} else {
result.vendor = util.getValue(lines, 'manufacturer', '=');
result.version = util.getValue(lines, 'version', '=');
}
result.releaseDate = util.getValue(lines, 'releasedate', '=');
if (result.releaseDate.length >= 10) {
result.releaseDate = result.releaseDate.substr(0, 4) + '-' + result.releaseDate.substr(4, 2) + '-' + result.releaseDate.substr(6, 2);
}
result.revision = util.getValue(lines, 'buildnumber', '=');
}
result.releaseDate = util.getValue(lines, 'releasedate', '=');
if (result.releaseDate.length >= 10) {
result.releaseDate = result.releaseDate.substr(0, 4) + '-' + result.releaseDate.substr(4, 2) + '-' + result.releaseDate.substr(6, 2);
}
result.revision = util.getValue(lines, 'buildnumber', '=');
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
resolve(result);
}
}
});
});
@ -350,26 +360,31 @@ function baseboard(callback) {
resolve(result);
}
if (_windows) {
exec(util.getWmic() + ' baseboard get /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');
result.manufacturer = util.getValue(lines, 'manufacturer', '=');
result.model = util.getValue(lines, 'model', '=');
if (!result.model) {
result.model = util.getValue(lines, 'product', '=');
try {
exec(util.getWmic() + ' baseboard get /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');
result.manufacturer = util.getValue(lines, 'manufacturer', '=');
result.model = util.getValue(lines, 'model', '=');
if (!result.model) {
result.model = util.getValue(lines, 'product', '=');
}
result.version = util.getValue(lines, 'version', '=');
result.serial = util.getValue(lines, 'serialnumber', '=');
result.assetTag = util.getValue(lines, 'partnumber', '=');
if (!result.assetTag) {
result.assetTag = util.getValue(lines, 'sku', '=');
}
}
result.version = util.getValue(lines, 'version', '=');
result.serial = util.getValue(lines, 'serialnumber', '=');
result.assetTag = util.getValue(lines, 'partnumber', '=');
if (!result.assetTag) {
result.assetTag = util.getValue(lines, 'sku', '=');
}
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
resolve(result);
}
}
});
});

View File

@ -245,15 +245,20 @@ function users(callback) {
});
}
if (_windows) {
exec('query user', opts, function (error, stdout) {
if (stdout) {
// lines / split
let lines = stdout.toString().split('\r\n');
result = parseUsersWin(lines);
}
try {
exec('query user', opts, function (error, stdout) {
if (stdout) {
// lines / split
let lines = stdout.toString().split('\r\n');
result = parseUsersWin(lines);
}
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
});
resolve(result);
}
}
});