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.
This is my code:
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
I write it in the costructor of my main project before InitializeComponent(). I've got Admin permission set in the .manifest file
Thanks to all, BlackShawarna
EDIT: I discovered that the RegistryKey.SetValue(...); created a key in another path:
(@"SOFTWARE\Wow6432Node\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);
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....");
If I run my program only in x64 mode, going to properties/build/x64, it won't write the key in my original path.
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".
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();
The executableName is something like "myAppName.exe"
Note: If the WebBrowser Controls inside a DLL you need to specify the hosting EXE's name whatever that might be, eg System.AppDomain.CurrentDomain.FriendlyName
FEATURE_BROWSER_EMULATION
"myAppName.exe"=10000
(or 0x02710) and not 1000.
In HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
and HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
It works for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With