windows refactor wmic
This commit is contained in:
parent
d1b6a17deb
commit
d023709d35
@ -162,7 +162,7 @@ module.exports = function (callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value').then((stdout, error) => {
|
||||
if (stdout) {
|
||||
let lines = stdout.split('\r\n');
|
||||
let status = util.getValue(lines, 'BatteryStatus', '=').trim();
|
||||
|
||||
@ -76,7 +76,7 @@ function fsSize(callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' logicaldisk get Caption,FileSystem,FreeSpace,Size', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout, error) => {
|
||||
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
|
||||
lines.forEach(function (line) {
|
||||
if (line !== '') {
|
||||
@ -261,7 +261,7 @@ function blockDevices(callback) {
|
||||
if (_windows) {
|
||||
let drivetypes = ['Unknown', 'NoRoot', 'Removable', 'Local', 'Network', 'CD/DVD', 'RAM'];
|
||||
try {
|
||||
util.execWin(util.getWmic() + ' logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let devices = stdout.toString().split(/\n\s*\n/);
|
||||
devices.forEach(function (device) {
|
||||
@ -883,7 +883,7 @@ function diskLayout(callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' diskdrive get /value', { encoding: 'utf8', windowsHide: true }, function (error, stdout) {
|
||||
util.wmic('diskdrive get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let devices = stdout.toString().split(/\n\s*\n/);
|
||||
devices.forEach(function (device) {
|
||||
|
||||
@ -472,11 +472,11 @@ function graphics(callback) {
|
||||
if (_windows) {
|
||||
// https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/
|
||||
try {
|
||||
util.execWin(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let csections = stdout.split(/\n\s*\n/);
|
||||
result.controllers = parseLinesWindowsControllers(csections);
|
||||
util.execWin(util.getWmic() + ' path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value').then((stdout, error) => {
|
||||
let dsections = stdout.split(/\n\s*\n/);
|
||||
if (!error) {
|
||||
result.displays = parseLinesWindowsDisplays(dsections);
|
||||
|
||||
@ -218,7 +218,7 @@ function mem(callback) {
|
||||
let swaptotal = 0;
|
||||
let swapused = 0;
|
||||
try {
|
||||
exec(util.getWmic() + ' pagefile get AllocatedBaseSize, CurrentUsage', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('pagefile get AllocatedBaseSize, CurrentUsage').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0);
|
||||
lines.forEach(function (line) {
|
||||
@ -356,7 +356,7 @@ function memLayout(callback) {
|
||||
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('|');
|
||||
|
||||
try {
|
||||
exec(util.getWmic() + ' memorychip get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('memorychip get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let devices = stdout.toString().split('BankL');
|
||||
devices.shift();
|
||||
|
||||
@ -651,8 +651,7 @@ function networkStatsSingle(iface) {
|
||||
let ifaceName = iface;
|
||||
|
||||
// Performance Data
|
||||
cmd = util.getWmic() + ' path Win32_PerfRawData_Tcpip_NetworkInterface Get name,BytesReceivedPersec,BytesSentPersec,BytesTotalPersec,PacketsOutboundDiscarded,PacketsOutboundErrors,PacketsReceivedDiscarded,PacketsReceivedErrors /value';
|
||||
exec(cmd, util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('path Win32_PerfRawData_Tcpip_NetworkInterface Get name,BytesReceivedPersec,BytesSentPersec,BytesTotalPersec,PacketsOutboundDiscarded,PacketsOutboundErrors,PacketsReceivedDiscarded,PacketsReceivedErrors /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const psections = stdout.toString().split(/\n\s*\n/);
|
||||
perfData = parseLinesWindowsPerfData(psections);
|
||||
|
||||
@ -281,7 +281,7 @@ function osInfo(callback) {
|
||||
result.logofile = getLogoFile();
|
||||
result.release = result.kernel;
|
||||
try {
|
||||
util.execWin(util.getWmic() + ' os get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('os get /value').then((stdout, error) => {
|
||||
let lines = stdout.toString().split('\r\n');
|
||||
result.distro = util.getValue(lines, 'Caption', '=').trim();
|
||||
result.serial = util.getValue(lines, 'SerialNumber', '=').trim();
|
||||
@ -514,7 +514,7 @@ function versions(callback) {
|
||||
});
|
||||
} else {
|
||||
if (_windows) {
|
||||
exec(util.getWmic() + ' service get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('service get /value').then((stdout, error) => {
|
||||
let serviceSections = stdout.split(/\n\s*\n/);
|
||||
for (let i = 0; i < serviceSections.length; i++) {
|
||||
if (serviceSections[i].trim() !== '') {
|
||||
|
||||
@ -247,7 +247,7 @@ function services(srv, callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' service get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('service get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let serviceSections = stdout.split(/\n\s*\n/);
|
||||
for (let i = 0; i < serviceSections.length; i++) {
|
||||
@ -664,7 +664,7 @@ function processes(callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' process get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('process get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let processSections = stdout.split(/\n\s*\n/);
|
||||
let procs = [];
|
||||
@ -790,7 +790,7 @@ function processLoad(proc, callback) {
|
||||
if (proc) {
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' process get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('process get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let processSections = stdout.split(/\n\s*\n/);
|
||||
let procStats = [];
|
||||
|
||||
@ -207,7 +207,7 @@ function system(callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' csproduct get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('csproduct get /value').then((stdout, 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');
|
||||
@ -216,7 +216,7 @@ function system(callback) {
|
||||
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', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('/namespace:\\\\root\\wmi path MS_SystemInformation get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let lines = stdout.split('\r\n');
|
||||
result.sku = util.getValue(lines, 'systemsku', '=');
|
||||
@ -295,7 +295,7 @@ function bios(callback) {
|
||||
if (_windows) {
|
||||
// TODO: check BIOS windows
|
||||
try {
|
||||
exec(util.getWmic() + ' bios get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('bios get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\r\n');
|
||||
const description = util.getValue(lines, 'description', '=');
|
||||
@ -403,7 +403,7 @@ function baseboard(callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' baseboard get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('baseboard get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\r\n');
|
||||
|
||||
@ -527,7 +527,7 @@ function chassis(callback) {
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
exec(util.getWmic() + ' path Win32_SystemEnclosure get /value', util.execOptsWin, function (error, stdout) {
|
||||
util.wmic('path Win32_SystemEnclosure get /value').then((stdout, error) => {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\r\n');
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user