Webbrowser control ignores FEATURE_BROWSER_EMULATION reg entry

独自空忆成欢 提交于 2019-12-02 01:02:18

The WebBrowser control definately DOES respect these keys.

Remember that while taskman may show application.exe in the name column, if you are debugging the exe name is application.vshost.exe

So in my application sI just attempt to create the key every time the app runs. If it fails to create it (because it already exists) then I continue running, if it creates the key then I inform the user that they need to restart the application.

ensure that you are not running within vshost

the app name would be different ie appname.vshost.exe

Thx for your reply, now its working.

Her is my working peace of code:

public void setIEcomp()
    {
        String appname = Process.GetCurrentProcess().ProcessName+".exe";
        RegistryKey RK8 = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION",RegistryKeyPermissionCheck.ReadWriteSubTree);            
        int value9 = 9999;
        int value8 = 8888;
        Version ver = webBrowser1.Version;
        int value = value9;
        try
        {
            string[] parts = ver.ToString().Split('.');
            int vn = 0;
            int.TryParse(parts[0], out vn);
            if (vn != 0)
            {
                if (vn == 9)
                    value = value9;
                else
                    value = value8;
            }
        }
        catch
        {
            value = value9;
        }
        //Setting the key in LocalMachine
        if (RK8 != null)
        {
            try
            {
                RK8.SetValue(appname, value, RegistryValueKind.DWord);
                RK8.Close();
            }
            catch(Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
        }
    }

I too could not see that FEATURE_BROWSER_EMULATION made any difference in my application.

I was testing the FEATURE_BROWSER_EMULATION functionality by manually editing the registry with regedit. Nothing I did made any difference. My hosted page was still failing on any new-ish JavaScript and could not load external libraries.

I found my mistake:

I was editing the 64-bit view of the registry with regedit. My app was running as a 32-bit app and looking at the 32-bit view of the registry. That's why my changes to the registry seemed to have no impact on my application. By the way, the WPF project template defaults to "Prefer 32-bit."

Manually editing with regedit within the Wow6432Node key worked:

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

Of course, setting the DWORD value programmatically within your application will also work, since your 32-bit application will edit within the Wow6432Node.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!