Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows 10将被捕获为Windows 8/Windows 8.1_C#_Version_Windows 10 - Fatal编程技术网

C# Windows 10将被捕获为Windows 8/Windows 8.1

C# Windows 10将被捕获为Windows 8/Windows 8.1,c#,version,windows-10,C#,Version,Windows 10,我有一个返回操作系统版本的程序 如果在Windows 10上运行,它会将其检测为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.OSVersi

我有一个返回操作系统版本的程序

如果在
Windows 10
上运行,它会将其检测为
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.";

    }
在其他代码中,我看到Windows10应该是
major==10
,但它似乎是
major==6&&minor==2&&build==9200
。 在Windows7中,它可以正常工作


因为我不使用VS 2015,也无法将客户端更新到
Windows 8.1 SDK
,所以老问题中的
IsWindows10OrGreater
解决方案对我不起作用

我记不起这个页面,但据我记忆所及,Windows 10正在返回603作为其版本NT,这与Windows 8相同。。。基本上赢10认为赢8

看看这个

因此,在您的条件语句中,Windows 10被捕获为Windows 8,因为它位于语句的末尾。这是Microsoft提供的解决方案:


要检测您是否在Windows 10上运行,您需要将这些兼容性标记添加到您的项目中,并根据需要插入这些兼容性标记:

<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>


如果您没有通过清单声明您的应用程序与Windows 10兼容,框架将始终假装您在Windows 8.1上运行。几周前我们遇到了同样的问题,并通过添加包含这些兼容性标记的清单解决了这个问题。

您的代码似乎是正确的。你绝对确定你在Windows 10的机器上运行它吗?是的,我肯定它是Windows 10。我在工作区选项中检查了它@马格德:这似乎是同样的问题。我将使用这个答案。非常感谢。我想得到操作系统的版本。但对于这段代码,它只与兼容。我可以从这段代码中获取版本吗?不,你的代码是正确的,只是如果你没有通过带有我发布的兼容性标记的清单声明你的程序集与Windows 10兼容,框架不会告诉你它是Windows 10。你是对的。这个很好用!