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 上运行
基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01