bugfix WMIC not found (Windows)

This commit is contained in:
Sebastian Hildebrandt 2017-12-14 11:20:32 +01:00
parent be8c3a97c1
commit ef4aa50fae
11 changed files with 36 additions and 21 deletions

View File

@ -99,6 +99,7 @@ Other changes
| Version | Date | Comment | | Version | Date | Comment |
| -------------- | -------------- | -------- | | -------------- | -------------- | -------- |
| 3.33.9 | 2017-12-14 | bugfix WMIC not found (Windows) |
| 3.33.8 | 2017-12-02 | bugfix diskLayout().size (OSX) | | 3.33.8 | 2017-12-02 | bugfix diskLayout().size (OSX) |
| 3.33.7 | 2017-11-28 | bugfix diskLayout().size | | 3.33.7 | 2017-11-28 | bugfix diskLayout().size |
| 3.33.6 | 2017-11-16 | bugfix diskLayout().size | | 3.33.6 | 2017-11-16 | bugfix diskLayout().size |

View File

@ -101,7 +101,7 @@ module.exports = function (callback) {
}); });
} }
if (_windows) { if (_windows) {
exec('WMIC Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value', function (error, stdout) { exec(util.getWmic() + ' Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value', function (error, stdout) {
if (stdout) { if (stdout) {
let lines = stdout.split('\r\n'); let lines = stdout.split('\r\n');
let status = util.getValue(lines, 'BatteryStatus', '=').trim(); let status = util.getValue(lines, 'BatteryStatus', '=').trim();

View File

@ -234,7 +234,7 @@ function getCpu() {
}); });
} }
if (_windows) { if (_windows) {
exec('wmic cpu get name, description, revision, l2cachesize, l3cachesize, manufacturer, currentclockspeed, maxclockspeed /value', function (error, stdout) { exec(util.getWmic() + ' cpu get name, description, revision, l2cachesize, l3cachesize, manufacturer, currentclockspeed, maxclockspeed /value', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.split('\r\n'); let lines = stdout.split('\r\n');
let name = util.getValue(lines, 'name', '=') || ''; let name = util.getValue(lines, 'name', '=') || '';
@ -278,7 +278,7 @@ function getCpu() {
} }
} }
} }
exec('wmic path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) { exec(util.getWmic() + ' path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) { lines.forEach(function (line) {
@ -448,7 +448,7 @@ function cpuTemperature(callback) {
resolve(result); resolve(result);
} }
if (_windows) { if (_windows) {
exec('wmic /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature', function (error, stdout) { exec(util.getWmic() + ' /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature', function (error, stdout) {
if (!error) { if (!error) {
let sum = 0; let sum = 0;
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
@ -595,7 +595,7 @@ function cpuCache(callback) {
}); });
} }
if (_windows) { if (_windows) {
exec('wmic cpu get l2cachesize, l3cachesize /value', function (error, stdout) { exec(util.getWmic() + ' cpu get l2cachesize, l3cachesize /value', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.split('\r\n'); let lines = stdout.split('\r\n');
result.l1d = 0; result.l1d = 0;
@ -605,7 +605,7 @@ function cpuCache(callback) {
if (result.l2) { result.l2 = parseInt(result.l2) * 1024; } if (result.l2) { result.l2 = parseInt(result.l2) * 1024; }
if (result.l3) { result.l3 = parseInt(result.l3) * 1024; } if (result.l3) { result.l3 = parseInt(result.l3) * 1024; }
} }
exec('wmic path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) { exec(util.getWmic() + ' path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) { lines.forEach(function (line) {

View File

@ -62,7 +62,7 @@ function fsSize(callback) {
}); });
} }
if (_windows) { if (_windows) {
exec('wmic logicaldisk get Caption,FileSystem,FreeSpace,Size', function (error, stdout) { exec(util.getWmic() + ' logicaldisk get Caption,FileSystem,FreeSpace,Size', function (error, stdout) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) { lines.forEach(function (line) {
if (line !== '') { if (line !== '') {
@ -237,7 +237,7 @@ function blockDevices(callback) {
}); });
} }
if (_windows) { if (_windows) {
exec('wmic logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /format:csv', function (error, stdout) { exec(util.getWmic() + ' logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /format:csv', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) { lines.forEach(function (line) {
@ -698,7 +698,7 @@ function diskLayout(callback) {
} }
if (_windows) { if (_windows) {
exec('wmic diskdrive get /value', function (error, stdout) { exec(util.getWmic() + ' diskdrive get /value', function (error, stdout) {
if (!error) { if (!error) {
let devices = stdout.toString().split('\r\n\r\n\r\n'); let devices = stdout.toString().split('\r\n\r\n\r\n');
devices.forEach(function (device) { devices.forEach(function (device) {

View File

@ -323,11 +323,11 @@ function graphics(callback) {
} }
if (_windows) { if (_windows) {
// https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/ // https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/
exec('wmic path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', function (error, stdout) { exec(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', function (error, stdout) {
if (!error) { if (!error) {
let csections = stdout.split(/\n\s*\n/); let csections = stdout.split(/\n\s*\n/);
result.controllers = parseLinesWindowsControllers(csections); result.controllers = parseLinesWindowsControllers(csections);
exec('wmic path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value', function (error, stdout) { exec(util.getWmic() + ' path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value', function (error, stdout) {
let dsections = stdout.split(/\n\s*\n/); let dsections = stdout.split(/\n\s*\n/);
if (!error) { if (!error) {
result.displays = parseLinesWindowsDisplays(dsections); result.displays = parseLinesWindowsDisplays(dsections);

View File

@ -164,7 +164,7 @@ function mem(callback) {
if (_windows) { if (_windows) {
let swaptotal = 0; let swaptotal = 0;
let swapused = 0; let swapused = 0;
exec('wmic pagefile get AllocatedBaseSize, CurrentUsage', function (error, stdout) { exec(util.getWmic() + ' pagefile get AllocatedBaseSize, CurrentUsage', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
lines.forEach(function (line) { lines.forEach(function (line) {
@ -293,7 +293,7 @@ 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 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('|'); 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('wmic memorychip get BankLabel, Capacity, ConfiguredClockSpeed, ConfiguredVoltage, MaxVoltage, MinVoltage, DataWidth, FormFactor, Manufacturer, MemoryType, PartNumber, SerialNumber, Speed, Tag /value', function (error, stdout) { exec(util.getWmic() + 'wmic memorychip get BankLabel, Capacity, ConfiguredClockSpeed, ConfiguredVoltage, MaxVoltage, MinVoltage, DataWidth, FormFactor, Manufacturer, MemoryType, PartNumber, SerialNumber, Speed, Tag /value', function (error, stdout) {
if (!error) { if (!error) {
let devices = stdout.toString().split('BankL'); let devices = stdout.toString().split('BankL');
devices.shift(); devices.shift();

View File

@ -319,14 +319,14 @@ function networkStats(iface, callback) {
// NICs // NICs
let perfData = []; let perfData = [];
let nics = []; let nics = [];
cmd = 'wmic nic get MACAddress, name, NetEnabled /value'; cmd = util.getWmic() + ' nic get MACAddress, name, NetEnabled /value';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
const nsections = stdout.split(/\n\s*\n/); const nsections = stdout.split(/\n\s*\n/);
nics = parseLinesWindowsNics(nsections); nics = parseLinesWindowsNics(nsections);
// Performance Data // Performance Data
cmd = 'wmic path Win32_PerfRawData_Tcpip_NetworkInterface Get name,BytesReceivedPersec,BytesSentPersec,BytesTotalPersec /value'; cmd = util.getWmic() + ' path Win32_PerfRawData_Tcpip_NetworkInterface Get name,BytesReceivedPersec,BytesSentPersec,BytesTotalPersec /value';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
const psections = stdout.split(/\n\s*\n/); const psections = stdout.split(/\n\s*\n/);

View File

@ -14,6 +14,7 @@
const os = require('os'); const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const util = require('./util');
let _platform = os.type(); let _platform = os.type();
@ -203,7 +204,7 @@ function osInfo(callback) {
if (_windows) { if (_windows) {
result.logofile = getLogoFile(); result.logofile = getLogoFile();
result.release = result.kernel; result.release = result.kernel;
exec('wmic os get Caption', function (error, stdout) { exec(util.getWmic() + ' os get Caption', function (error, stdout) {
result.distro = result.codename = stdout.slice(stdout.indexOf('\r\n') + 2).trim(); result.distro = result.codename = stdout.slice(stdout.indexOf('\r\n') + 2).trim();
if (callback) { if (callback) {
callback(result); callback(result);

View File

@ -116,7 +116,7 @@ function services(srv, callback) {
} }
} }
if (_windows) { if (_windows) {
exec('wmic service get /value', {maxBuffer: 1024 * 1000}, function (error, stdout) { exec(util.getWmic() + ' service get /value', {maxBuffer: 1024 * 1000}, function (error, stdout) {
if (!error) { if (!error) {
let serviceSections = stdout.split(/\n\s*\n/); let serviceSections = stdout.split(/\n\s*\n/);
for (let i = 0; i < serviceSections.length; i++) { for (let i = 0; i < serviceSections.length; i++) {
@ -480,7 +480,7 @@ function processes(callback) {
}); });
} }
if (_windows) { if (_windows) {
exec('wmic process get /value', {maxBuffer: 1024 * 1000}, function (error, stdout) { exec(util.getWmic() + ' process get /value', {maxBuffer: 1024 * 1000}, function (error, stdout) {
if (!error) { if (!error) {
let processSections = stdout.split(/\n\s*\n/); let processSections = stdout.split(/\n\s*\n/);
let procs = []; let procs = [];

View File

@ -161,7 +161,7 @@ function system(callback) {
if (_windows) { if (_windows) {
// exec('wmic csproduct get', function (error, stdout) { // exec('wmic csproduct get', function (error, stdout) {
// ToDo: refactor /value // ToDo: refactor /value
exec('wmic csproduct get /value', function (error, stdout) { exec(util.getWmic() + ' csproduct get /value', function (error, stdout) {
if (!error) { 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').filter(line => line.trim() !== '').filter((line, idx) => idx > 0)[0].trim().split(/\s\s+/);
let lines = stdout.split('\r\n'); let lines = stdout.split('\r\n');
@ -222,7 +222,7 @@ function bios(callback) {
} }
if (_windows) { if (_windows) {
// ToDo: check BIOS windows // ToDo: check BIOS windows
exec('wmic bios get /value', function (error, stdout) { exec(util.getWmic() + ' bios get /value', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\r\n'); let lines = stdout.toString().split('\r\n');
const description = util.getValue(lines, 'description', '='); const description = util.getValue(lines, 'description', '=');
@ -308,7 +308,7 @@ function baseboard(callback) {
} }
if (_windows) { if (_windows) {
// ToDo: check BIOS windows // ToDo: check BIOS windows
exec('wmic baseboard get /value', function (error, stdout) { exec(util.getWmic() + ' baseboard get /value', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\r\n'); let lines = stdout.toString().split('\r\n');

View File

@ -13,7 +13,10 @@
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
const os = require('os'); const os = require('os');
const fs = require('fs');
let _cores = 0; let _cores = 0;
let wmic = '';
function isFunction(functionToCheck) { function isFunction(functionToCheck) {
let getType = {}; let getType = {};
@ -121,6 +124,15 @@ function parseDateTime(dt) {
return result; return result;
} }
function getWmic() {
if (os.type() === 'Windows_NT' && !wmic) {
if (fs.existsSync(process.env.WINDIR + '\\system32\\wbem\\wmic.exe')) {
wmic = process.env.WINDIR + '\\system32\\wbem\\wmic.exe';
} else wmic = 'wmic'
}
return wmic;
}
exports.isFunction = isFunction; exports.isFunction = isFunction;
exports.unique = unique; exports.unique = unique;
exports.sortByKey= sortByKey; exports.sortByKey= sortByKey;
@ -128,3 +140,4 @@ exports.cores = cores;
exports.getValue = getValue; exports.getValue = getValue;
exports.decodeEscapeSequence = decodeEscapeSequence; exports.decodeEscapeSequence = decodeEscapeSequence;
exports.parseDateTime = parseDateTime; exports.parseDateTime = parseDateTime;
exports.getWmic = getWmic;