问题描述
我正在寻找一种方法来检测我的 C# 应用程序是否在 Windows 10 上运行.
我曾希望 Environment.OSVersion 能解决问题,但这似乎在 Windows 8.1 上返回 6.3.9600.0 的 Version和 Windows 10.
如果它是 Windows 10,则使用此代码:
static bool IsWindows10(){var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindows NTCurrentVersion");string productName = (string)reg.GetValue("ProductName");return productName.StartsWith("Windows 10");}注意:将 using Microsoft.Win32; 添加到您的使用中.
I'm looking for a means to detect if my C# app is running on 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.
Other solutions such as this don't seem to distinguish between Windows 8 and Windows 10 either.
Any suggestions?
Why do I need to do this?
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...).
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_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProductName
For example my product name is Windows 10 Home:
With this code you get if it Windows 10:
static bool IsWindows10()
{
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindows NTCurrentVersion");
string productName = (string)reg.GetValue("ProductName");
return productName.StartsWith("Windows 10");
}
Note: Add using Microsoft.Win32; to your usings.
这篇关于如何检测我的应用程序是否在 Windows 10 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)