none
W2K12 R2, Environment.OSVersion delivers wrong os RRS feed

  • Question

  • Hello,

    I'm running trivial C# code (Framework 4.0) on a W2K12 R2 Server:

    string _OS = Environment.OSVersion.Version.ToString();
    Version _ver = Environment.OSVersion.Version;
    int _OS_Version = _ver.Major * 10 + _ver.Minor;
    Console.WriteLine(_OS + ":  " + _OS_Version.ToString());
    Console.ReadLine();

    I get result "6.2.9200.0:  62", but I was expecting "6.3 ...".

    Output of the "ver" command is "Microsoft Windows [Version 6.3.9600]".

    Registry value "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion" has content "6.3".

    Registry value "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName" has content "Windows Server 2012 R2 Standard".

    I tried it on different W2K12 R2 machines, but always getting wrong result.

    I hope you could help.

    Regards, Thomas

    Wednesday, March 12, 2014 2:21 PM

Answers

  • Environment.OSVersion uses GetVersionEx.  This API has been modified starting with Win 8.1/Win 2012 R2 to return Win 8/Win 2012 unless the application has been modified to identify support for later versions as discussed in the API documentation.  The specific example is given here.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    • Marked as answer by thsc007 Friday, March 14, 2014 3:01 PM
    Wednesday, March 12, 2014 5:29 PM
    Moderator

All replies

  • Environment.OSVersion uses GetVersionEx.  This API has been modified starting with Win 8.1/Win 2012 R2 to return Win 8/Win 2012 unless the application has been modified to identify support for later versions as discussed in the API documentation.  The specific example is given here.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    • Marked as answer by thsc007 Friday, March 14, 2014 3:01 PM
    Wednesday, March 12, 2014 5:29 PM
    Moderator
  • After adding the following lines to my manfest file it works fine:

        <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
            <application>
                <!-- Windows 8.1 -->
                <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
                <!-- 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}"/>
            </application>
        </compatibility>

    Thank you very much.

    Friday, March 14, 2014 3:02 PM