Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Environment.OSVersion returns wrong version

Tags:

c#

Using windows 10, upgraded from windows 8 => 8.1 => 10 When I use this code.

OperatingSystem os = System.Environment.OSVersion; 

The os.Version = {6.2.9200.0} System.Version

I read this was because of the version it was manifested for but I do not understand what that means.

I want the correct OS version because I am logging a user agent string on a web service, and want to correctly identify the windows version for support. what is the easiest way to get that to correctly report the correct version?

like image 251
pgee70 Avatar asked Oct 25 '15 10:10

pgee70


1 Answers

Windows 10 returns that string unless you declare that your application is compatible using a manifest. To do so add an app.manifest (right click your project -> Add -> New Item -> Application Manifest File) then uncomment the following line:

<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> 

You can do the same thing for Windows Vista to Windows 10. All are in the same section:

<application>   <!-- A list of the Windows versions that this application has been tested on and is        is designed to work with. Uncomment the appropriate elements and Windows will         automatically selected the most compatible environment. -->    <!-- Windows Vista -->   <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->    <!-- Windows 7 -->   <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->    <!-- Windows 8 -->   <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->    <!-- Windows 8.1 -->   <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->    <!-- Windows 10 -->   <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />  </application> 

And now when you run your application it'll report the correct 10.0.*.0 version

like image 80
Nasreddine Avatar answered Oct 11 '22 18:10

Nasreddine