.NET application that returns a different version of PowerShell in Windows 10

I am trying to determine the OS version in a .NET application that already uses System.Environment.OSVersion to successfully determine the version for all versions of Windows prior to Windows 8.1.

However, when you call System.Environment.OSVersion in a .NET application in Windows 10, the returned version of Microsoft Windows NT 6.2.9200.0 (this is exactly the same output as in Windows 8.1). However, when I call [System.Environment]::OSVersion via PowerShell, the output gives me Microsoft Windows NT 10.0.10240.0 .

I got the impression that PowerShell uses .NET under the hood and expects both calls to return exactly the same result. Why is there a mismatch in the output and, more importantly, how can I determine if my application is running on Windows 10?

+7
c # windows powershell windows-10
source share
1 answer

I think this is the reason :

With the release of Windows 8.1, the behavior of the GetVersion API GetVersion changed in the value that it will return for the version of the operating system. The value returned by the GetVersion function now depends on how the application appears.

Applications that are not displayed for Windows 8.1 or Windows 10 will return the value of the version of Windows 8 (6.2).

+8
source share

All Articles