You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[environment]::OSVersion.Version returns a wrong result of the OS #2009
Nah the reason is NOT using GetVersionEx. It works fine in Windows 10. You're referring to a right documentation though. The exe of that PowerShell lacks manifestation, as you can see it is reporting Windows 8.1.
GetVersionInfo seems not to be a Win32 API, can you find a documentation on it? As far as I know, Microsoft only recommends using version helper functions (hmmm I'd have to say many programmers aren't logical enough to correctly check version numbers so MS is providing helper functions haha). And for getting the native system information, use GetFileVersionInfo. GetVersionEx returns the compatibility mode version number and if the app is not manifested for Windows 8.1/10, VersionLie shim gets in.
and is furthermore currently based on calls to the deprecated-since-Windows-8.1 GetVersion and GetVersionEx Windows API functions, which as has been pointed out, do not report the true OS version.
Ji Luo (@GeeLaw): The Core powershell.exe does have an (embedded) manifest too, but one without entries targeting specific Windows version, hence it is "stuck" at reporting Windows 8 (6.2), as you state.
That said, even the Windows PowerShell powershell.exe, with its Windows-version-targeting entries would be lied to in the future, if it used GetVersion(Ex)directly:
"Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases." -
However, it seems that the .NET Framework (I presume) works around this:
/*
SystemNative::GetOSVersion - Fcall corresponding to System.Environment.GetVersion
It calls clr!GetOSVersion to get the real OS version even when running in
app compat. Calling kernel32!GetVersionEx() directly will be shimmed and will return the
fake OS version. In order to avoid this the call to getVersionEx is made via mscoree.dll.
Mscoree.dll resides in system32 dir and is never lied about OS version.
*/
It sounds like .NET Core, which I presume doesn't use mscoree.dll, cannot take advantage of this, which is why the Core edition reports the fake version.
call the GetFileVersionInfo function on one of the system DLLs, such as Kernel32.dll, then call VerQueryValue to obtain the \StringFileInfo\\ProductVersion sub-block of the file version information."
To put it in PowerShell terms (Windows-only): (Get-FileVersionInfo $env:SystemRoot\System32\kernel32.dll).ProductVersion
Activity
GeeLaw commentedon Aug 22, 2016
Nah the reason is NOT using GetVersionEx. It works fine in Windows 10. You're referring to a right documentation though. The exe of that PowerShell lacks manifestation, as you can see it is reporting Windows 8.1.
GetVersionInfo seems not to be a Win32 API, can you find a documentation on it? As far as I know, Microsoft only recommends using version helper functions (hmmm I'd have to say many programmers aren't logical enough to correctly check version numbers so MS is providing helper functions haha). And for getting the native system information, use GetFileVersionInfo. GetVersionEx returns the compatibility mode version number and if the app is not manifested for Windows 8.1/10, VersionLie shim gets in.
daxian-dbw commentedon Aug 22, 2016
[environment]::OSVersion.Versionis actually calling .NET Core code:System.Environment::OSVersion is not exposed in .NET Core contract, but it's obviously still preserved in the runtime assembly.
.NET Core team will bring back OSVersion and other public surface from
System.Private.Corelibin .NET Core 1.1 release, see dotnet-core#6006SteveL-MSFT commentedon Oct 28, 2016
we are doing work to expose OS info in psversiontable #1635 , this is already tracked in dotnet repo
mklement0 commentedon Mar 22, 2017
Just a heads-up that, at least as of this writing, while dotnet-core#6006 does intend to bring
System.Environment'sOSVersionback:its implementation is not cross-platform yet,
and is furthermore currently based on calls to the deprecated-since-Windows-8.1
GetVersionandGetVersionExWindows API functions, which as has been pointed out, do not report the true OS version.powershell.exedoes have an (embedded) manifest too, but one without entries targeting specific Windows version, hence it is "stuck" at reporting Windows 8 (6.2), as you state.That said, even the Windows PowerShell
powershell.exe, with its Windows-version-targeting entries would be lied to in the future, if it usedGetVersion(Ex)directly:It sounds like .NET Core, which I presume doesn't use
mscoree.dll, cannot take advantage of this, which is why the Core edition reports the fake version.It is hard to believe, but the method that the official docs recommend for determining the true Windows version number is:
To put it in PowerShell terms (Windows-only):
(Get-FileVersionInfo $env:SystemRoot\System32\kernel32.dll).ProductVersion