BlackShawarna
BlackShawarna

Reputation: 277

webbrowser using ie10 c# winform

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.

Upvotes: 5

Views: 9095

Answers (4)

bendi
bendi

Reputation: 133

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

Upvotes: 9

xibabababa
xibabababa

Reputation: 71

If you have control over the page being rendered (a intranet page for instance) and also of the application that renders the page using the WebBrowser control, you can specify a meta tag in the page

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

and make use of the WebBrowser control as needed. You must have IE 10 on the machine.

Just in case you want to emulate other versions of IE, you could simply replace "IE=10" with "IE=EmulateIE9", "IE=EmulateIE8" etc.

Upvotes: 0

SingleStepper
SingleStepper

Reputation: 348

You've got to say 'myAppName.exe' not 'myAppName'

Upvotes: 0

florian69666
florian69666

Reputation: 31

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

Upvotes: 3

Related Questions