我怎样才能检测是否我的应用程序在Windows 10上运行, [英] How can I detect if my app is running on Windows 10

查看:273
本文介绍了我怎样才能检测是否我的应用程序在Windows 10上运行,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方式,如果我的C#应用​​程序在Windows 10上运行,以检测。

I'm looking for a means to detect if my C# app is running on Windows 10.

我曾希望 Environment.OSVersion 会做的伎俩,但这似乎返回版本 6.3.9600.0 对是Windows 8.1和Windows 10。

I had hoped that Environment.OSVersion would do the trick, but this seems to return a Version of 6.3.9600.0 on Windows 8.1 and Windows 10.

其他的解决方案,如的这似乎不能在Windows 8和Windows 10或者区别开来。

Other solutions such as this don't seem to distinguish between Windows 8 and Windows 10 either.

有什么建议?

为什么我要这么做?

由于我使用的WinForms WebBrowser控件来承载一个OAuth页面崩溃和烧伤老年IE版本(我的应用程序连接到用户的鸟巢帐户 ... )。

Because I'm using a WinForms WebBrowser control to host an OAuth page that crashes and burns in older IE versions (my app connects to a user's Nest account...).

默认情况下,WebBrowser控件模拟IE7。使用注册表项,你可以告诉它来模拟已安装在主机上的IE浏览器的最新版本。但是,值工作达到Windows 8.1(和Windows 10的预发行版)无法在Windows 10的最终版本。

By default, the WebBrowser control emulates IE7. Using a Registry key, you can tell it to emulate the latest version of IE that is installed on the host PC. However, the value that worked up to Windows 8.1 (and pre-releases of Windows 10) does not work in the final version of Windows 10.

推荐答案

如果你看一下注册表,你会发现环境名称:

If you look at registry you will found environment name:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName

例如我的产品名称为视窗10首页

有了这个代码,你会得到,如果它的Windows 10:

With this code you get if it 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");
 }

请注意:添加使用的Microsoft.Win32; 您usings。

Note: Add using Microsoft.Win32; to your usings.

这篇关于我怎样才能检测是否我的应用程序在Windows 10上运行,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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