使用C#在Windows 10中获取当前版本的OS [英] Get current version OS in Windows 10 in C#

查看:656
本文介绍了使用C#在Windows 10中获取当前版本的OS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#.我尝试获取当前版本的操作系统:

I Use C#. I try to get the current version of the OS:

OperatingSystem os = Environment.OSVersion;
Version ver = os.Version;

我进入 Windows 10 : 6.2 .

但是 6.2 Windows 8 WindowsServer 2012 (我找到了以下解决方案(如何检测我的应用程序是否在Windows 10上运行).

I found the following solution (How can I detect if my app is running on Windows 10).

static bool IsWindows10()
{
  var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
  string productName = (string)reg.GetValue("ProductName");
  return productName.StartsWith("Windows 10");
}

这是在C#中获取当前版本的最佳方法?

This is the best way to get the current version in C#?

推荐答案

添加 Windows 8.1和Windows 10的受支持的操作系统ID 到清单:

Add application manifest to your application and add the supportedOS Id of Windows 8.1 and Windows 10 to the manifest:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
        <application> 
            <!-- Windows 10 --> 
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
            <!-- Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
        </application> 
    </compatibility>

现在Environment.OSVersion包含适用于Windows 8.1和Windows 10的正确数据,而不是6.2,以指示您运行Windows8.这是

Now Environment.OSVersion includes the correct data for Windows 8.1 and Windows 10 and not 6.2 to indicate you run Windows 8. This is a change since Windows 8.1.

这篇关于使用C#在Windows 10中获取当前版本的OS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆