Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET app returning different OS version to PowerShell on Windows 10

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?

like image 570
alimbada Avatar asked Aug 20 '15 14:08

alimbada


People also ask

What version of .NET does PowerShell use?

Windows PowerShell 5.1 is built on top of the . NET Framework v4. 5.

How do I get the OS version of Windows using PowerShell?

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.

Where is PowerShell located Windows 10?

From the Start menu, click Start, click All Programs, click Accessories, click the Windows PowerShell folder, and then click Windows PowerShell.

What version is Windows 2009?

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.


1 Answers

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).

like image 157
Anton Gogolev Avatar answered Oct 23 '22 20:10

Anton Gogolev