diff --git a/lib/audio.js b/lib/audio.js index 4b519fd..e632c95 100644 --- a/lib/audio.js +++ b/lib/audio.js @@ -194,7 +194,7 @@ function audio(callback) { }); } if (_windows) { - util.wmic('path Win32_SoundDevice get /value', function (error, stdout) { + util.wmic('path Win32_SoundDevice get /value').then((stdout, error) => { if (!error) { const parts = stdout.toString().split(/\n\s*\n/); for (let i = 0; i < parts.length; i++) { diff --git a/lib/bluetooth.js b/lib/bluetooth.js index bc05b08..cef989f 100644 --- a/lib/bluetooth.js +++ b/lib/bluetooth.js @@ -158,7 +158,7 @@ function bluetoothDevices(callback) { }); } if (_windows) { - util.wmic('path Win32_PNPEntity get /value', function (error, stdout) { + util.wmic('path Win32_PNPEntity get /value').then((stdout, error) => { if (!error) { const parts = stdout.toString().split(/\n\s*\n/); for (let i = 0; i < parts.length; i++) { diff --git a/lib/printer.js b/lib/printer.js index 05265a2..5246b19 100644 --- a/lib/printer.js +++ b/lib/printer.js @@ -186,7 +186,7 @@ function printer(callback) { }); } if (_windows) { - util.wmic('printer get /value', function (error, stdout) { + util.wmic('printer get /value').then((stdout, error) => { if (!error) { const parts = stdout.toString().split(/\n\s*\n/); for (let i = 0; i < parts.length; i++) { diff --git a/lib/usb.js b/lib/usb.js index 5d1511c..2b547ef 100644 --- a/lib/usb.js +++ b/lib/usb.js @@ -263,7 +263,7 @@ function usb(callback) { }); } if (_windows) { - util.wmic('Path CIM_LogicalDevice where "Description like \'USB%\'" get /value', function (error, stdout) { + util.wmic('Path CIM_LogicalDevice where "Description like \'USB%\'" get /value').then((stdout, error) => { if (!error) { const parts = stdout.toString().split(/\n\s*\n/); for (let i = 0; i < parts.length; i++) { diff --git a/lib/util.js b/lib/util.js index 94a30be..5952034 100644 --- a/lib/util.js +++ b/lib/util.js @@ -319,14 +319,13 @@ function getWmic() { return wmicPath; } -function wmic(command, options) { - options = options || execOptsWin; +function wmic(command) { return new Promise((resolve) => { process.nextTick(() => { try { - exec(WINDIR + '\\system32\\chcp.com 65001 | ' + getWmic() + ' ' + command, options, function (error, stdout) { - resolve(stdout, error); - }).stdin.end(); + powerShell(getWmic() + ' ' + command).then(stdout => { + resolve(stdout, ''); + }); } catch (e) { resolve('', e); } @@ -334,6 +333,21 @@ function wmic(command, options) { }); } +// function wmic(command, options) { +// options = options || execOptsWin; +// return new Promise((resolve) => { +// process.nextTick(() => { +// try { +// exec(WINDIR + '\\system32\\chcp.com 65001 | ' + getWmic() + ' ' + command, options, function (error, stdout) { +// resolve(stdout, error); +// }).stdin.end(); +// } catch (e) { +// resolve('', e); +// } +// }); +// }); +// } + function getVboxmanage() { return _windows ? `"${process.env.VBOX_INSTALL_PATH || process.env.VBOX_MSI_INSTALL_PATH}\\VBoxManage.exe"` : 'vboxmanage'; }