5

我想强制 webbrowser 在我的 c# winform 应用程序中使用 IE10。我知道还有其他类似的问题,但我已经阅读了很多,但我不知道我错在哪里。

这是我的代码:

RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
           (@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
        registrybrowser.SetValue("myAppName", 0x02710, RegistryValueKind.DWord); //Even with QWord

我尝试了不同的方法来设置值,例如:

registrybrowser.SetValue("myAppName", 1000, RegistryValueKind.DWord); //Even with QWord and String
registrybrowser.SetValue("myAppName", 1000); //even with 0x02710

我在 InitializeComponent() 之前将它写在我的主项目的构造函数中。我在 .manifest 文件中设置了管理员权限

感谢所有人, BlackShawarna

编辑:我发现 RegistryKey.SetValue(...); 在另一个路径中创建了一个键:

(@"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION") 

即使我的指示说:Registry.LocalMachine.OpenSubKey (@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);

我认为这是因为 IE10 在 32 位模式下工作。但是,即使我指定了另一个路径,我也不明白为什么它会写入该路径,最重要的是,为什么即使我打开 Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node...." );

如果我只在 x64 模式下运行我的程序,转到 properties/build/x64,它不会在我的原始路径中写入密钥。

4

4 回答 4

9

我的应用程序将值写入“HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION”时遇到了同样的问题。

我将 LocalMachine 更改为 CurrentUser,现在它可以工作了。

string executablePath = Environment.GetCommandLineArgs()[0];
string executableName = System.IO.Path.GetFileName(executablePath);

RegistryKey registrybrowser = Registry.CurrentUser.OpenSubKey
   (@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);

if (registrybrowser == null)
{
    RegistryKey registryFolder = Registry.CurrentUser.OpenSubKey
        (@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl", true);
    registrybrowser = registryFolder.CreateSubKey("FEATURE_BROWSER_EMULATION");
}
registrybrowser.SetValue(executableName, 0x02710, RegistryValueKind.DWord);
registrybrowser.Close();

可执行文件名称类似于“myAppName.exe”

注意:如果 DLL 中的 WebBrowser 控件,您需要指定宿主 EXE 的名称,无论它可能是什么,例如System.AppDomain.CurrentDomain.FriendlyName

于 2013-10-16T13:32:34.903 回答
3

FEATURE_BROWSER_EMULATION "myAppName.exe"=10000(或 0x02710)而不是 1000。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

这个对我有用

于 2013-07-26T13:11:07.950 回答
0

你必须说“myAppName.exe”而不是“myAppName”

于 2013-10-12T18:33:29.470 回答
0

如果您可以控制正在呈现的页面(例如 Intranet 页面)以及使用 WebBrowser 控件呈现页面的应用程序,则可以在页面中指定元标记

<meta http-equiv="X-UA-Compatible" content="IE=10" />

并根据需要使用 WebBrowser 控件。您必须在机器上安装 IE 10。

万一您想模拟其他版本的 IE,您可以简单地替换"IE=10""IE=EmulateIE9""IE=EmulateIE8"

于 2015-06-09T21:38:04.093 回答