How can I detect if my app is running on Windows 10(如何检测我的应用程序是否在 Windows 10 上运行)
问题描述
我正在寻找一种方法来检测我的 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 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检测我的应用程序是否在 Windows 10 上运行


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01