I'm trying to determine the OS version in a .NET application which already uses System.Environment.OSVersion to successfully determine the version for all versions of Windows up to Windows 8.1.
However, when calling System.Environment.OSVersion
in a .NET app on Windows 10, the version returned is Microsoft Windows NT 6.2.9200.0
(which is exactly the same output as on Windows 8.1). However, when calling [System.Environment]::OSVersion
via PowerShell the output gives me Microsoft Windows NT 10.0.10240.0
.
I was under the impression that PowerShell uses .NET under the hood and expected both calls to return exactly the same output. Why is there a discrepancy in the output and more importantly, how can I detect if my app is running on Windows 10?
Windows PowerShell 5.1 is built on top of the . NET Framework v4. 5.
To find out the Windows version, you can utilize the following PowerShell “Get-ComputerInfo” command, “Get-ItemProperty” command, “systeminfo” command, “System. Environment” command, and “Get-CimInstance” command. All of these commands can display the Windows version along with other related information.
From the Start menu, click Start, click All Programs, click Accessories, click the Windows PowerShell folder, and then click Windows PowerShell.
The Windows 10 20H2 update, also known as version 2009, is pegged as a cumulative update to the Windows 10 operating system that will activate many of the still-dormant features within Windows 10 version 2004, which began rolling out to customers in late May.
I think this is the cause:
With the release of Windows 8.1, the behavior of the
GetVersion
API has changed in the value it will return for the operating system version. The value returned by the GetVersion function now depends on how the application is manifested.Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With