Windows XP WMIC support
This commit is contained in:
parent
398b08ea88
commit
d1b6a17deb
10
lib/cpu.js
10
lib/cpu.js
@ -429,7 +429,7 @@ function getCpu() {
|
|||||||
}
|
}
|
||||||
if (_windows) {
|
if (_windows) {
|
||||||
try {
|
try {
|
||||||
exec(util.getWmic() + ' cpu get /value', util.execOptsWin, function (error, stdout) {
|
util.wmic('cpu get /value').then((stdout, error) => {
|
||||||
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', '=') || '';
|
||||||
@ -489,7 +489,7 @@ function getCpu() {
|
|||||||
result.physicalCores = parseInt(countCores) || util.cores();
|
result.physicalCores = parseInt(countCores) || util.cores();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exec(util.getWmic() + ' path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) {
|
util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose').then((stdout, error) => {
|
||||||
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) {
|
||||||
@ -701,7 +701,7 @@ function cpuTemperature(callback) {
|
|||||||
}
|
}
|
||||||
if (_windows) {
|
if (_windows) {
|
||||||
try {
|
try {
|
||||||
exec(util.getWmic() + ' /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature', util.execOptsWin, function (error, stdout) {
|
util.wmic('/namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature').then((stdout, error) => {
|
||||||
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);
|
||||||
@ -929,7 +929,7 @@ function cpuCache(callback) {
|
|||||||
}
|
}
|
||||||
if (_windows) {
|
if (_windows) {
|
||||||
try {
|
try {
|
||||||
exec(util.getWmic() + ' cpu get l2cachesize, l3cachesize /value', util.execOptsWin, function (error, stdout) {
|
util.wmic('cpu get l2cachesize, l3cachesize /value').then((stdout, error) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.split('\r\n');
|
let lines = stdout.split('\r\n');
|
||||||
result.l1d = 0;
|
result.l1d = 0;
|
||||||
@ -939,7 +939,7 @@ function cpuCache(callback) {
|
|||||||
if (result.l2) { result.l2 = parseInt(result.l2, 10) * 1024; }
|
if (result.l2) { result.l2 = parseInt(result.l2, 10) * 1024; }
|
||||||
if (result.l3) { result.l3 = parseInt(result.l3, 10) * 1024; }
|
if (result.l3) { result.l3 = parseInt(result.l3, 10) * 1024; }
|
||||||
}
|
}
|
||||||
exec(util.getWmic() + ' path Win32_CacheMemory get CacheType,InstalledSize,Purpose', function (error, stdout) {
|
util.wmic('path Win32_CacheMemory get CacheType,InstalledSize,Purpose').then((stdout, error) => {
|
||||||
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) {
|
||||||
|
|||||||
34
lib/util.js
34
lib/util.js
@ -28,7 +28,7 @@ const _openbsd = (_platform === 'openbsd');
|
|||||||
// const _sunos = (_platform === 'sunos');
|
// const _sunos = (_platform === 'sunos');
|
||||||
|
|
||||||
let _cores = 0;
|
let _cores = 0;
|
||||||
let wmic = '';
|
let wmicPath = '';
|
||||||
let codepage = '';
|
let codepage = '';
|
||||||
|
|
||||||
const execOptsWin = {
|
const execOptsWin = {
|
||||||
@ -220,16 +220,39 @@ function findObjectByKey(array, key, value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getWmic() {
|
function getWmic() {
|
||||||
if (os.type() === 'Windows_NT' && !wmic) {
|
if (os.type() === 'Windows_NT' && !wmicPath) {
|
||||||
try {
|
try {
|
||||||
wmic = execSync('WHERE WMIC').toString().trim();
|
wmicPath = execSync('WHERE WMIC').toString().trim();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (fs.existsSync(process.env.WINDIR + '\\system32\\wbem\\wmic.exe')) {
|
if (fs.existsSync(process.env.WINDIR + '\\system32\\wbem\\wmic.exe')) {
|
||||||
wmic = process.env.WINDIR + '\\system32\\wbem\\wmic.exe';
|
wmic = process.env.WINDIR + '\\system32\\wbem\\wmic.exe';
|
||||||
} else wmic = 'wmic';
|
} else wmicPath = 'wmic';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return wmic;
|
return wmicPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
function wmic(command, options) {
|
||||||
|
options = options || execOptsWin;
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
process.nextTick(() => {
|
||||||
|
try {
|
||||||
|
exec(getWmic() + ' ' + command, options, function (error, stdout) {
|
||||||
|
resolve(stdout, error)
|
||||||
|
// resolve({
|
||||||
|
// stdout,
|
||||||
|
// error
|
||||||
|
// });
|
||||||
|
}).stdin.end();
|
||||||
|
} catch (e) {
|
||||||
|
resolve('', e)
|
||||||
|
// resolve({
|
||||||
|
// stdout: '',
|
||||||
|
// error: e
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerShell(cmd) {
|
function powerShell(cmd) {
|
||||||
@ -384,6 +407,7 @@ exports.parseDateTime = parseDateTime;
|
|||||||
exports.parseHead = parseHead;
|
exports.parseHead = parseHead;
|
||||||
exports.findObjectByKey = findObjectByKey;
|
exports.findObjectByKey = findObjectByKey;
|
||||||
exports.getWmic = getWmic;
|
exports.getWmic = getWmic;
|
||||||
|
exports.wmic = wmic;
|
||||||
exports.powerShell = powerShell;
|
exports.powerShell = powerShell;
|
||||||
exports.nanoSeconds = nanoSeconds;
|
exports.nanoSeconds = nanoSeconds;
|
||||||
exports.countUniqueLines = countUniqueLines;
|
exports.countUniqueLines = countUniqueLines;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user