39

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?

Irshad
  • 3,071
  • 5
  • 30
  • 51
pgee70
  • 3,707
  • 4
  • 35
  • 41

4 Answers4

45

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

Nasreddine
  • 36,610
  • 17
  • 75
  • 94
  • Thanks, that worked for a debug compile, but when i compile for release it still returns the windows 8.1 version. "NT 6.2". what have i missed? – pgee70 Oct 25 '15 at 12:29
  • 3
    @pgee70 There's nothing more to it. I tried on my end and it works both in release and debug. Just make sure that it's the right exe you're deploying and in your project configuration in the Application tab that the correct manifest is included as you can see [here](http://i.imgur.com/WxuZ8KW.png?1) – Nasreddine Oct 25 '15 at 12:54
  • Any idea how to do this for .net core? – jjxtra Jul 20 '18 at 01:08
  • In a windows only application it is easy to add the manifest using Visual studio. – TazAstroSpacial Nov 08 '18 at 05:56
2

The sequence of steps given by Nasreddine will add a manifest file, into your project.

There is another way to add a manifest. Right click project > properties > Application tab > View Windows Settings This will bring up the default manifest, which you can edit. I am using visual studio 2010 Express. From other reading the method should be similar.

For a project that uses non-windows components (I program in ESRI arc-objcets with VB.Net) there seems to be no way of adding a manifest file. The View Windows Settings button is disabled. The steps given by Nasreddine do add a Manifest file which can be edited but this cannot be incorporated into the project. I have tried many tricks: like adding as a resource (embedded and not embedded), adding it the obj > debug folder.

The kicker test was I set up a pure windows project, got a windo button comand to return the correct version string (after adding a manifest) then tried to add an non-windows component (ESRI Addin). this failed with an error message.

I am was just trying to identify the OS because the file location of required files is dependent on operating system. Hope this save others from going down this rabbit hole.

2

Another alternative is

Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem + " " + Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion

Microsoft.DotNet.PlatformAbstractions NuGet package reference is needed

Tal Aloni
  • 1,429
  • 14
  • 14
-1

Try:

new ComputerInfo().OSVersion;

Output:

Microsoft Windows 10 Enterprise

Note: Add reference to Microsoft.VisualBasic.Devices;

Thanks to https://stackoverflow.com/a/39888998/6629672

Almenon
  • 1,191
  • 11
  • 22