我正在寻找一种方法来检测我的 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 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!