问题描述
我要强制web浏览器在我的C#WinForm应用程序使用IE10。
我知道有这样的其他问题,但我已经读了很多人,我不知道我错了。
I want to force the webbrowser to use IE10 in my c# winform application.I know there are other questions like this but i've already read a lot of them and i don't know where i'm wrong.
这是我的代码:
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
registrybrowser.SetValue("myAppName", 0x02710, RegistryValueKind.DWord); //Even with QWord
我已经尝试了不同的方式来设置类似的值:
I've tried different ways to set the value like:
registrybrowser.SetValue("myAppName", 1000, RegistryValueKind.DWord); //Even with QWord and String
registrybrowser.SetValue("myAppName", 1000); //even with 0x02710
我把它写在我的主体工程costructor的InitializeComponent()之前。
我已经得到了文件名为.manifest管理员权限集
I write it in the costructor of my main project before InitializeComponent().I've got Admin permission set in the .manifest file
感谢所有,BlackShawarna
Thanks to all, BlackShawarna
编辑:我发现RegistryKey.SetValue(...);创造了另一条道路的关键:
I discovered that the RegistryKey.SetValue(...); created a key in another path:
(@"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION")
即使我的指令说.OpenSubKey
(@SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION,真正的);
even if my instruction said: Registry.LocalMachine.OpenSubKey (@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
我想这是因为IE10工作在32位模式。不过,我不明白为什么在这条道路写道,即使我指定一个又一个,首先,为什么即使我打开Registry.LocalMachine.OpenSubKey(@Software\Wow6432Node我的应用程序无法正常工作.... );
I think it happens because IE10 works on 32bit mode. However I don't understand why it writes in that path even if i specified another one and, above all, why my application doesn't work even if I open Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node....");
如果我只能在64位模式下运行我的程序,将性能/建设/ X64,它不会写在我的原路径的关键
If I run my program only in x64 mode, going to properties/build/x64, it won't write the key in my original path.
推荐答案
我有我的应用程序写的价值同样的问题,以HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet资源管理器\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION。
I had the same problem that my app wrote the value to "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION".
我改变LOCALMACHINE到的currentUser,现在它的作品。
I changed LocalMachine to CurrentUser and now it works.
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();
executableName是一样的东西作为SingleStepper提到的myAppName.exe
executableName is something like "myAppName.exe" as SingleStepper mentioned
这篇关于web浏览器IE10使用C#的winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!