added windows exec 'windowsHide' option

This commit is contained in:
Sebastian Hildebrandt 2018-02-19 22:07:20 +01:00
parent fc7348cc56
commit a15af92453
14 changed files with 79 additions and 41 deletions

View File

@ -11,9 +11,6 @@ end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
# trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = true
[{.travis.yml,package.json}]

View File

@ -100,6 +100,7 @@ Other changes
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 3.37.3 | 2018-02-19 | added windows exec 'windowsHide' option |
| 3.37.2 | 2018-02-15 | fixed bug `battery().percent` for macOS |
| 3.37.1 | 2018-02-13 | fixed bug `battery().ischarging` for macOS |
| 3.37.0 | 2018-02-11 | extended FreeBSD support `networkStats()` |

View File

@ -559,6 +559,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra
- Tiago Roldão [tiagoroldao](https://github.com/tiagoroldao)
- dragonjet [dragonjet](https://github.com/dragonjet)
- Adam Reis [adamreisnz](https://github.com/adamreisnz)
- Jimmi M [ItsJimi](https://github.com/ItsJimi)
OSX Temperature: credits here are going to:

View File

@ -24,6 +24,10 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
module.exports = function (callback) {
return new Promise((resolve) => {
@ -123,7 +127,7 @@ module.exports = function (callback) {
});
}
if (_windows) {
exec(util.getWmic() + ' Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value', function (error, stdout) {
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();

View File

@ -25,6 +25,10 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
let _cpu_speed = '0.00';
let _current_cpu = {
user: 0,
@ -298,7 +302,7 @@ function getCpu() {
});
}
if (_windows) {
exec(util.getWmic() + ' 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', opts, function (error, stdout) {
if (!error) {
let lines = stdout.split('\r\n');
let name = util.getValue(lines, 'name', '=') || '';
@ -534,7 +538,7 @@ function cpuTemperature(callback) {
resolve(result);
}
if (_windows) {
exec(util.getWmic() + ' /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature', function (error, stdout) {
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);

View File

@ -26,6 +26,10 @@ const _openbsd = (_platform === 'openbsd');
const NOT_SUPPORTED = 'not supported';
const opts = {
windowsHide: true
};
let _fs_speed = {};
let _disk_io = {};
@ -69,7 +73,7 @@ function fsSize(callback) {
});
}
if (_windows) {
exec(util.getWmic() + ' logicaldisk get Caption,FileSystem,FreeSpace,Size', function (error, stdout) {
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 !== '') {
@ -245,7 +249,7 @@ 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', function (error, stdout) {
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) {
@ -712,7 +716,7 @@ function diskLayout(callback) {
}
if (_windows) {
exec(util.getWmic() + ' diskdrive get /value', {encoding: 'utf8'}, function (error, stdout) {
exec(util.getWmic() + ' diskdrive get /value', {encoding: 'utf8'}, opts, function (error, stdout) {
if (!error) {
let devices = stdout.toString().split(/\n\s*\n/);
devices.forEach(function (device) {

View File

@ -23,6 +23,10 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
let _resolutionx = 0;
let _resolutiony = 0;
let _pixeldepth = 0;
@ -329,11 +333,11 @@ 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', function (error, stdout) {
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', function (error, stdout) {
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);

View File

@ -24,6 +24,9 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
const OSX_RAM_manufacturers = {
'0x014F': 'Transcend Information',
@ -191,7 +194,7 @@ function mem(callback) {
if (_windows) {
let swaptotal = 0;
let swapused = 0;
exec(util.getWmic() + ' pagefile get AllocatedBaseSize, CurrentUsage', function (error, stdout) {
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) {
@ -320,7 +323,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 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', function (error, stdout) {
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();

View File

@ -26,6 +26,10 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
let _network = {};
let _default_iface;
let _mac = {};
@ -349,14 +353,14 @@ function networkStats(iface, callback) {
let perfData = [];
let nics = [];
cmd = util.getWmic() + ' nic get MACAddress, name, NetEnabled /value';
exec(cmd, function (error, stdout) {
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, function (error, stdout) {
exec(cmd, opts, function (error, stdout) {
if (!error) {
const psections = stdout.split(/\n\s*\n/);
perfData = parseLinesWindowsPerfData(psections);
@ -565,7 +569,7 @@ function networkConnections(callback) {
}
if (_windows) {
let cmd = 'netstat -na';
exec(cmd, function (error, stdout) {
exec(cmd, opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');

View File

@ -24,6 +24,10 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
const NOT_SUPPORTED = 'not supported';
// --------------------------
@ -226,7 +230,7 @@ function osInfo(callback) {
if (_windows) {
result.logofile = getLogoFile();
result.release = result.kernel;
exec(util.getWmic() + ' os get Caption', function (error, stdout) {
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);

View File

@ -24,6 +24,10 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
const NOT_SUPPORTED = 'not supported';
let _process_cpu = {
@ -120,7 +124,7 @@ function services(srv, callback) {
}
}
if (_windows) {
exec(util.getWmic() + ' service get /value', {maxBuffer: 1024 * 1000}, function (error, stdout) {
exec(util.getWmic() + ' service get /value', {maxBuffer: 1024 * 1000}, opts, function (error, stdout) {
if (!error) {
let serviceSections = stdout.split(/\n\s*\n/);
for (let i = 0; i < serviceSections.length; i++) {
@ -489,7 +493,7 @@ function processes(callback) {
});
}
if (_windows) {
exec(util.getWmic() + ' process get /value', {maxBuffer: 1024 * 1000}, function (error, stdout) {
exec(util.getWmic() + ' process get /value', {maxBuffer: 1024 * 1000}, opts, function (error, stdout) {
if (!error) {
let processSections = stdout.split(/\n\s*\n/);
let procs = [];

View File

@ -24,6 +24,10 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
function system(callback) {
return new Promise((resolve) => {
@ -161,7 +165,7 @@ function system(callback) {
if (_windows) {
// exec('wmic csproduct get', function (error, stdout) {
// ToDo: refactor /value
exec(util.getWmic() + ' csproduct get /value', function (error, stdout) {
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');
@ -222,7 +226,7 @@ function bios(callback) {
}
if (_windows) {
// ToDo: check BIOS windows
exec(util.getWmic() + ' bios get /value', function (error, stdout) {
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', '=');
@ -308,7 +312,7 @@ function baseboard(callback) {
}
if (_windows) {
// ToDo: check BIOS windows
exec(util.getWmic() + ' baseboard get /value', function (error, stdout) {
exec(util.getWmic() + ' baseboard get /value', opts, function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\r\n');

View File

@ -23,6 +23,10 @@ const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const opts = {
windowsHide: true
};
// --------------------------
// array of users online = sessions
@ -229,7 +233,7 @@ function users(callback) {
});
}
if (_windows) {
exec('query user', function (error, stdout) {
exec('query user', opts, function (error, stdout) {
if (stdout) {
// lines / split
let lines = stdout.toString().split('\r\n');

View File

@ -23,29 +23,29 @@ function isFunction(functionToCheck) {
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
}
function unique(obj){
let uniques=[];
let stringify={};
for(let i=0;i<obj.length;i++){
let keys=Object.keys(obj[i]);
keys.sort(function(a,b) { return a-b; });
let str='';
for(let j=0;j<keys.length;j++){
str+= JSON.stringify(keys[j]);
str+= JSON.stringify(obj[i][keys[j]]);
function unique(obj) {
let uniques = [];
let stringify = {};
for (let i = 0; i < obj.length; i++) {
let keys = Object.keys(obj[i]);
keys.sort(function (a, b) { return a - b; });
let str = '';
for (let j = 0; j < keys.length; j++) {
str += JSON.stringify(keys[j]);
str += JSON.stringify(obj[i][keys[j]]);
}
if(!stringify.hasOwnProperty(str)){
if (!stringify.hasOwnProperty(str)) {
uniques.push(obj[i]);
stringify[str]=true;
stringify[str] = true;
}
}
return uniques;
}
function sortByKey(array, keys) {
return array.sort(function(a, b) {
let x ='';
let y ='';
return array.sort(function (a, b) {
let x = '';
let y = '';
keys.forEach(function (key) {
x = x + a[key]; y = y + b[key];
});
@ -84,7 +84,7 @@ function getValue(lines, property, separator, trimmed) {
function decodeEscapeSequence(str, base) {
base = base || 16;
return str.replace(/\\x([0-9A-Fa-f]{2})/g, function() {
return str.replace(/\\x([0-9A-Fa-f]{2})/g, function () {
return String.fromCharCode(parseInt(arguments[1], base));
});
}
@ -133,11 +133,11 @@ function getWmic() {
return wmic;
}
function noop(){}
function noop() { }
exports.isFunction = isFunction;
exports.unique = unique;
exports.sortByKey= sortByKey;
exports.sortByKey = sortByKey;
exports.cores = cores;
exports.getValue = getValue;
exports.decodeEscapeSequence = decodeEscapeSequence;