我正在使用 VS 2013 和C#网络浏览器控件,但是当我在Windows 8和更早版本(例如Windows 7,安装了Internet Explorer 8)上运行.exe文件时,然后打开{{3 }}页面上显示“您的浏览器是旧的,请更新它”。
我用三种方法更改了注册表设置,但无法正常工作。
第一个代码及其链接:
private void SetIE11KeyforWebBrowserControl()
{
var appName = Process.GetCurrentProcess().ProcessName + ".exe";
RegistryKey Regkey = null;
try
{
// For 64 bit machine
if (Environment.Is64BitOperatingSystem)
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@ "SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EM ULATION", true);
else //For 32 bit machine
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@ "SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EM ULATION", true);
// If the path is not correct or
// if the user haven't priviledges to access the registry
if (Regkey == null)
{
if (Environment.Is64BitOperatingSystem)
Regkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey (@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EM ULATION");
else //For 32 bit machine
Regkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey (@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EM ULATION");
}
string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
// Check if key is already present
if (FindAppkey == "11000")
{
Regkey.Close();
//MessageBox.Show("Application set IE Key value");
return;
}
else
{
Regkey.SetValue(appName, unchecked((int)0x2AF8), RegistryValueKind.DWord);
}
// Check for the key after adding
FindAppkey = Convert.ToString(Regkey.GetValue(appName));
if (FindAppkey != "11000")
throw new Exception("Can not set IE key for web browser");
else
{
Regkey.Close();
//MessageBox.Show("Application set IE Key value");
}
}
catch (Exception ex)
{
MessageBox.Show("Application Settings Failed\n" + ex.Message);
}
finally
{
// Close the Registry
if (Regkey != null)
Regkey.Close();
}
第二个代码:
public class Helper
{
public static void SetBrowserEmulation(
string programName, IE browserVersion)
{
if (string.IsNullOrEmpty(programName))
{
programName = AppDomain.CurrentDomain.FriendlyName;
RegistryKey regKey = Registry.CurrentUser.OpenSubKey(
"Software\\Microsoft\\Internet Explorer\\Main" +
"\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
if (regKey != null)
{
try
{
regKey.SetValue(programName, browserVersion,
RegistryValueKind.DWord);
}
catch (Exception ex)
{
throw new Exception("Error writing to the registry", ex);
}
}
else
{
try
{
regKey = Registry.CurrentUser.OpenSubKey("Software" +
"\\Microsoft\\Internet Explorer\\Main" +
"\\FeatureControl", true);
regKey.CreateSubKey("FEATURE_BROWSER_EMULATION");
regKey.SetValue(programName, browserVersion,
RegistryValueKind.DWord);
}
catch (Exception ex)
{
throw new Exception("Error accessing the registry", ex);
}
}
}
}
}
public enum IE
{
IE7 = 7000,
IE8 = 8000,
IE8StandardsMode = 8888,
IE9 = 9000,
IE9StandardsMode = 9999,
IE10 = 10000,
IE10StandardsMode = 10001
}
第三个链接: 链接:Use latest version of Internet Explorer in the webbrowser control
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
"YourApplicationFileName.exe"=dword:00002af9
"YourApplicationFileName.vshost.exe"=dword:00002af9
更新1:
我正在使用默认的C#Web浏览器控件(基于IE的浏览器),How can I get the WebBrowser control to show modern contents?说:您的浏览器是“ Windows 7上的Internet Explorer 8”
更新2:
当我在Windows 7上安装IE 11时,我的.exe文件可以正常工作,但是我想使用代码(而不是安装IE11)更改设置。
答案 0 :(得分:0)
在阅读the link you provided时,要理解的关键是它没有为您提供IE的最新版本(即IE 11)-它为您提供了安装在计算机上的最新版本的IE 。
您的计算机已安装IE 8。由于C#Web浏览器控件使用与计算机安装版本相同的IE版本,因此您的C#应用程序正在使用IE 8。
不幸的是,谷歌地图不再支持IE 8。
因此,您有三组选项: