mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
more wmic replacements
Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
parent
0ec8b061c8
commit
b39235643e
6 changed files with 57 additions and 70 deletions
|
@ -800,32 +800,35 @@ function hexToAscii(hexString) {
|
|||
|
||||
function win_chassisType()
|
||||
{
|
||||
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'SystemEnclosure', 'get', 'ChassisTypes']);
|
||||
// needs to be replaced with win-wmi but due to bug in win-wmi it doesnt handle arrays correctly
|
||||
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], {});
|
||||
if (child == null) { return ([]); }
|
||||
child.descriptorMetadata = 'process-manager';
|
||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stdin.write('Get-CimInstance Win32_SystemEnclosure| Select-Object -ExpandProperty ChassisTypes\r\n');
|
||||
child.stdin.write('exit\r\n');
|
||||
child.waitExit();
|
||||
|
||||
try
|
||||
{
|
||||
var tok = child.stdout.str.split('{')[1].split('}')[0];
|
||||
var val = tok.split(',')[0];
|
||||
return (parseInt(val));
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
try {
|
||||
return (parseInt(child.stdout.str));
|
||||
} catch (e) {
|
||||
return (2); // unknown
|
||||
}
|
||||
}
|
||||
|
||||
function win_systemType()
|
||||
{
|
||||
var CSV = '/FORMAT:"' + require('util-language').wmicXslPath + 'csv"';
|
||||
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'ComputerSystem', 'get', 'PCSystemType', CSV]);
|
||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||
child.waitExit();
|
||||
try {
|
||||
var tokens = require('win-wmi').query('ROOT\\CIMV2', 'SELECT PCSystemType FROM Win32_ComputerSystem', ['PCSystemType']);
|
||||
if (tokens[0]) {
|
||||
return (parseInt(tokens[0]['PCSystemType']));
|
||||
} else {
|
||||
return (parseInt(1)); // default is desktop
|
||||
}
|
||||
} catch (ex) {
|
||||
return (parseInt(1)); // default is desktop
|
||||
}
|
||||
|
||||
return (parseInt(child.stdout.str.trim().split(',').pop()));
|
||||
}
|
||||
|
||||
function win_formFactor(chassistype)
|
||||
|
|
|
@ -229,25 +229,14 @@ function macos_memUtilization()
|
|||
function windows_thermals()
|
||||
{
|
||||
var ret = [];
|
||||
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', '/namespace:\\\\root\\wmi', 'PATH', 'MSAcpi_ThermalZoneTemperature', 'get', 'CurrentTemperature,InstanceName', '/FORMAT:CSV']);
|
||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||
child.waitExit();
|
||||
if(child.stdout.str.trim()!='')
|
||||
{
|
||||
var lines = child.stdout.str.trim().split('\r\n');
|
||||
var keys = lines[0].trim().split(',');
|
||||
for (var i = 1; i < lines.length; ++i)
|
||||
{
|
||||
var obj = {};
|
||||
var tokens = lines[i].trim().split(',');
|
||||
for (var key = 0; key < keys.length; ++key)
|
||||
{
|
||||
if (tokens[key]) { obj[keys[key]] = key==1 ? ((parseFloat(tokens[key]) / 10) - 273.15).toFixed(2) : tokens[key]; }
|
||||
try {
|
||||
ret = require('win-wmi').query('ROOT\\WMI', 'SELECT CurrentTemperature,InstanceName FROM MSAcpi_ThermalZoneTemperature',['CurrentTemperature','InstanceName']);
|
||||
if (ret[0]) {
|
||||
for (var i = 0; i < ret.length; ++i) {
|
||||
ret[i]['CurrentTemperature'] = ((parseFloat(ret[i]['CurrentTemperature']) / 10) - 273.15).toFixed(2);
|
||||
}
|
||||
ret.push(obj);
|
||||
}
|
||||
}
|
||||
} catch (ex) { }
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,28 +18,21 @@ var promise = require('promise');
|
|||
|
||||
function qfe()
|
||||
{
|
||||
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'qfe', 'list', 'full', '/FORMAT:CSV']);
|
||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||
child.waitExit();
|
||||
|
||||
var lines = child.stdout.str.trim().split('\r\n');
|
||||
var keys = lines[0].split(',');
|
||||
var i, key;
|
||||
var tokens;
|
||||
var result = [];
|
||||
|
||||
for (i = 1; i < lines.length; ++i)
|
||||
{
|
||||
var obj = {};
|
||||
tokens = lines[i].split(',');
|
||||
for (key = 0; key < keys.length; ++key)
|
||||
{
|
||||
if (tokens[key]) { obj[keys[key]] = tokens[key]; }
|
||||
try {
|
||||
var tokens = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_QuickFixEngineering');
|
||||
if (tokens[0]){
|
||||
for (var index = 0; index < tokens.length; index++) {
|
||||
for (var key in tokens[index]) {
|
||||
if (key.startsWith('__')) delete tokens[index][key];
|
||||
}
|
||||
}
|
||||
return (tokens);
|
||||
} else {
|
||||
return ([]);
|
||||
}
|
||||
result.push(obj);
|
||||
} catch (ex) {
|
||||
return ([]);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
function av()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue