From 193658a2ad4cbe8596c19f6b19cd29ca2e39b547 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 26 Aug 2021 14:40:11 +0200 Subject: [PATCH] osInfo() faster hyper-v detection (win) --- docs/index.html | 2 +- lib/osinfo.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/index.html b/docs/index.html index 8712129..ffc044e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -203,7 +203,7 @@
-
14,535
+
14,587
Lines of code
diff --git a/lib/osinfo.js b/lib/osinfo.js index 01d7b11..e85aa82 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -324,7 +324,8 @@ function osInfo(callback) { const workload = []; workload.push(util.wmic('os get /value')); // workload.push(execPromise('systeminfo', util.execOptsWin)); - workload.push(util.powerShell('Get-ComputerInfo -property "HyperV*"')); + // workload.push(util.powerShell('Get-ComputerInfo -property "HyperV*"')); + workload.push(util.powerShell('(Get-CimInstance Win32_ComputerSystem).HypervisorPresent')); workload.push(util.powerShell('Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SystemInformation]::TerminalServerSession')); util.promiseAll( workload @@ -336,9 +337,11 @@ function osInfo(callback) { result.servicepack = util.getValue(lines, 'ServicePackMajorVersion', '=').trim() + '.' + util.getValue(lines, 'ServicePackMinorVersion', '=').trim(); result.codepage = util.getCodepage(); // const systeminfo = data.results[1] ? data.results[1].toString() : ''; - // result.hypervisor = (systeminfo.indexOf('hypervisor has been detected') !== -1) || (systeminfo.indexOf('Es wurde ein Hypervisor erkannt') !== -1) || (systeminfo.indexOf('Un hyperviseur a ') !== -1); - const hyperv = data.results[1] ? data.results[1].toString().split('\r\n') : []; - result.hypervisor = (util.getValue(hyperv, 'HyperVisorPresent').toLowerCase() === 'true'); + // result.hypervisor = (systeminfo.indexOf('hypervisor has been detected') !== -1) || (systeminfo.indexOf('ein Hypervisor erkannt') !== -1) || (systeminfo.indexOf('Un hyperviseur a ') !== -1); + // const hyperv = data.results[1] ? data.results[1].toString().split('\r\n') : []; + // result.hypervisor = (util.getValue(hyperv, 'HyperVisorPresent').toLowerCase() === 'true'); + const hyperv = data.results[1] ? data.results[1].toString().toLowerCase() : ''; + result.hypervisor = hyperv.indexOf('true') !== -1; const term = data.results[2] ? data.results[2].toString() : ''; result.remoteSession = (term.toString().toLowerCase().indexOf('true') >= 0); isUefiWindows().then(uefi => {