0

I have a program which returns the OS version.

If run on a Windows 10, it detects it as as Windows 8|8.1.

public string GetWindwosClientVersion()  //Get OS Version and if 64 or 32 bit
    {
        int major = System.Environment.OSVersion.Version.Major;
        int minor = System.Environment.OSVersion.Version.Minor;
        int build = System.Environment.OSVersion.Version.Build;
        string bit;

        if (System.Environment.Is64BitOperatingSystem == true) //get 64 or 32 bit
        {
            bit = " 64bit";
        }
        else
        {
            bit = " 32bit";
        }
        if (major == 4 && minor == 0 && build == 950) 
            return "Win95 Release 1" + bit;
        else if (major == 4 && minor == 0 && build == 1111)
            return "Win95 Release 2" + bit;
        else if (major == 4 && minor == 3 && (build == 1212 || build == 1213 || build == 1214))
            return "Win95 Release 2.1" + bit;
        else if (major == 4 && minor == 10 && build == 1998)
            return "Win98" + bit;
        else if (major == 4 && minor == 10 && build == 2222)
            return "Win98 Second Edition" + bit;
        else if (major == 4 && minor == 90)
            return "WinMe" + bit;
        else if (major == 5 && minor == 0)
            return "Win2000" + bit;
        else if (major == 5 && minor == 1 && build == 2600)
            return "WinXP" + bit;
        else if (major == 6 && minor == 0)
            return "Vista" + bit;
        else if (major == 6 && minor == 1)
            return "Win7" + bit;
        else if (major == 6 && minor == 2 && build == 9200)
            return "Win8 | Win8.1" + bit;
        else if (major == 6 && minor == 2 && build == 9600)
            return "Win8.1 Update 1" + bit;
        else if (major == 10 && minor == 0 && build == 10240)
            return "Win10" + bit;
        else
            return "Can not find OS version.";

    }

In other codes I see that Windows 10 should be major == 10 but it seems to be major == 6 && minor == 2 && build == 9200. With Windows 7 it works fine.

Because I don't use VS 2015 and can't update the client to Windows 8.1 SDK, the IsWindows10OrGreater solution in the old question doesn't work for me!

Shadow
  • 25
  • 6
  • Your code seems right. Are you absolutely sure you are running it on a machine witn Windows 10? – Lars Kristensen Dec 07 '15 at 10:53
  • Yes i am sure it is Windows 10. I checked it in Workspace Options. @Marged it seems to be the same problem. I will work with this answer. Thank you! – Shadow Dec 07 '15 at 11:04

2 Answers2

2

To detect that you are running on a Windows 10, you need to add a manifest file to your project and insert these compatibility tags according to your needs:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
  <application>
    <!-- List of all Windows versions this app is compatible with -->
    <!-- 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>
</compatibility>

If you don't declare your app as compatible with Windows 10 via a manifest, the framework will always pretend you were running on a Windows 8.1. We had the same issue some weeks ago and solved it by adding a manifest containing these compatibility tags.

Community
  • 1
  • 1
René Vogt
  • 43,056
  • 14
  • 77
  • 99
  • I want to get the OS version. But with this code it is onliy compatible with. Can i get the version out of this code? – Shadow Dec 07 '15 at 11:10
  • No, your code is correct, except that the framework won't tell it's Windows 10 if you don't declare your assembly as compatible with Windows 10 via a manifest with the compatibility tags I posted. – René Vogt Dec 07 '15 at 11:11
  • You are right. This works fine! – Shadow Dec 07 '15 at 12:40
0

I can not recall the page, but as far as I remember Windows 10 is returning 603 for its VersionNT which is same as Windows 8 ... basically Win 10 thinks its Win 8.

Have a look at this https://social.technet.microsoft.com/Forums/en-US/1c8be9b3-a8be-4070-b8e9-51f3c5448c5c/windows-10-msi-installer-sets-versionntversionnt64-to-603-should-be-1000.

So in your conditional statement Windows 10 is being caught as Windows 8 simply because it is at the end of the statement. This is the solution from Microsoft:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn481241(v=vs.85).aspx

Ahmad
  • 1,462
  • 15
  • 23