Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed from WMIC to Powershell to detect if the OS is a server version #15

Open
wants to merge 5 commits into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -26,13 +26,21 @@ const windowsRelease = release => {

const ver = (version || [])[0];

// Server 2008, 2012 and 2016 versions are ambiguous with desktop versions and must be detected at runtime.
// Server 2008, 2012 and 2016, 2019 versions are ambiguous with desktop versions and must be detected at runtime.
// If `release` is omitted or we're on a Windows system, and the version number is an ambiguous version
// then use `wmic` to get the OS caption: https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx
// If the resulting caption contains the year 2008, 2012 or 2016, it is a server version, so return a server OS name.
// If `wmic` is obsoloete (later versions of Windows 10), use Powershell instead
// If the resulting caption contains the year 2008, 2012 or 2016, 2019 it is a server version, so return a server OS name.
if ((!release || release === os.release()) && ['6.1', '6.2', '6.3', '10.0'].includes(ver)) {
const stdout = execa.sync('wmic', ['os', 'get', 'Caption']).stdout || '';
let stdout;
try {
stdout = execa.sync('wmic', ['os', 'get', 'Caption']).stdout || '';
} catch (error) {
stdout = execa.sync('powershell', ['(Get-CimInstance -ClassName Win32_OperatingSystem).caption']).stdout || '';
}

const year = (stdout.match(/2008|2012|2016/) || [])[0];

if (year) {
return `Server ${year}`;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.