[c#] 웹 브라우저 컨트롤에서 최신 버전의 Internet Explorer 사용

C # Windows Forms
애플리케이션 에서 웹 브라우저 컨트롤의 기본 버전 은 7입니다. 브라우저 에뮬레이션 기사에서 9로 변경 했지만 웹 브라우저 컨트롤에서 설치된 Internet Explorer의 최신 버전을 어떻게 사용할 수 있습니까?



답변

나는 Veer의 대답을 보았다. 나는 그것이 옳다고 생각하지만 그것은 나를 위해 일하지 않았습니다. 아마도 .NET 4를 사용하고 있으며 64x OS를 사용하고 있으므로 친절하게 확인하십시오.

애플리케이션을 시작할 때 설정하거나 확인할 수 있습니다.

private void Form1_Load(object sender, EventArgs e)
{
    var appName = Process.GetCurrentProcess().ProcessName + ".exe";
    SetIE8KeyforWebBrowserControl(appName);
}

private void SetIE8KeyforWebBrowserControl(string appName)
{
    RegistryKey Regkey = null;
    try
    {
        // For 64 bit machine
        if (Environment.Is64BitOperatingSystem)
            Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
        else  //For 32 bit machine
            Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);

        // If the path is not correct or
        // if the user haven't priviledges to access the registry
        if (Regkey == null)
        {
            MessageBox.Show("Application Settings Failed - Address Not found");
            return;
        }

        string FindAppkey = Convert.ToString(Regkey.GetValue(appName));

        // Check if key is already present
        if (FindAppkey == "8000")
        {
            MessageBox.Show("Required Application Settings Present");
            Regkey.Close();
            return;
        }

        // If a key is not present add the key, Key value 8000 (decimal)
        if (string.IsNullOrEmpty(FindAppkey))
            Regkey.SetValue(appName, unchecked((int)0x1F40), RegistryValueKind.DWord);

        // Check for the key after adding
        FindAppkey = Convert.ToString(Regkey.GetValue(appName));

        if (FindAppkey == "8000")
            MessageBox.Show("Application Settings Applied Successfully");
        else
            MessageBox.Show("Application Settings Failed, Ref: " + FindAppkey);
    }
    catch (Exception ex)
    {
        MessageBox.Show("Application Settings Failed");
        MessageBox.Show(ex.Message);
    }
    finally
    {
        // Close the Registry
        if (Regkey != null)
            Regkey.Close();
    }
}

테스트 용으로 messagebox.show를 찾을 수 있습니다.

키는 다음과 같습니다.

  • 11001 (0x2AF9)-Internet Explorer 11. 웹 페이지가 !DOCTYPE지시문에 관계없이 IE11 에지 모드로 표시됩니다 .

  • 11000 (0x2AF8)-Internet Explorer 11. 표준 기반 !DOCTYPE지시문이 포함 된 웹 페이지가 IE11 에지 모드로 표시됩니다. IE11의 기본값입니다.

  • 10001 (0x2711)-Internet Explorer 10. 웹 페이지는 !DOCTYPE지시문에 관계없이 IE10 표준 모드로 표시됩니다 .

  • 10000 (0x2710)-Internet Explorer 10. 표준 기반 !DOCTYPE지시문이 포함 된 웹 페이지가
    IE10 표준 모드로 표시됩니다. Internet Explorer 10의 기본값입니다.

  • 9999 (0x270F) -Internet Explorer 9. 웹 페이지는 !DOCTYPE지시문에 관계없이 IE9 표준 모드로 표시됩니다 .

  • 9000 (0x2328)-Internet Explorer 9. 표준 기반 !DOCTYPE지시문이 포함 된 웹 페이지가 IE9 모드로 표시됩니다.

  • 8888 (0x22B8)!DOCTYPE지시문에 관계없이 웹 페이지가 IE8 표준 모드로 표시됩니다 .

  • 8000 (0x1F40) -표준 기반 !DOCTYPE
    지시문이 포함 된 웹 페이지가 IE8 모드로 표시됩니다.

  • 7000 (0x1B58) -표준 기반 !DOCTYPE
    지시문이 포함 된 웹 페이지가 IE7 표준 모드로 표시됩니다.

참조 : MSDN : 인터넷 기능 컨트롤

Skype와 같은 응용 프로그램이 10001을 사용하는 것을 봤습니다. 모르겠습니다.

노트

설치 응용 프로그램이 레지스트리를 변경합니다. 레지스트리 변경 권한으로 인한 오류를 방지하려면 매니페스트 파일에 줄을 추가해야 할 수 있습니다.

<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

업데이트 1

이 클래스는 Windows에서 최신 버전의 IE를 가져와야하는대로 변경합니다.

public class WebBrowserHelper
{


    public static int GetEmbVersion()
    {
        int ieVer = GetBrowserVersion();

        if (ieVer > 9)
            return ieVer * 1000 + 1;

        if (ieVer > 7)
            return ieVer * 1111;

        return 7000;
    } // End Function GetEmbVersion

    public static void FixBrowserVersion()
    {
        string appName = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location);
        FixBrowserVersion(appName);
    }

    public static void FixBrowserVersion(string appName)
    {
        FixBrowserVersion(appName, GetEmbVersion());
    } // End Sub FixBrowserVersion

    // FixBrowserVersion("<YourAppName>", 9000);
    public static void FixBrowserVersion(string appName, int ieVer)
    {
        FixBrowserVersion_Internal("HKEY_LOCAL_MACHINE", appName + ".exe", ieVer);
        FixBrowserVersion_Internal("HKEY_CURRENT_USER", appName + ".exe", ieVer);
        FixBrowserVersion_Internal("HKEY_LOCAL_MACHINE", appName + ".vshost.exe", ieVer);
        FixBrowserVersion_Internal("HKEY_CURRENT_USER", appName + ".vshost.exe", ieVer);
    } // End Sub FixBrowserVersion 

    private static void FixBrowserVersion_Internal(string root, string appName, int ieVer)
    {
        try
        {
            //For 64 bit Machine 
            if (Environment.Is64BitOperatingSystem)
                Microsoft.Win32.Registry.SetValue(root + @"\Software\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", appName, ieVer);
            else  //For 32 bit Machine 
                Microsoft.Win32.Registry.SetValue(root + @"\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", appName, ieVer);


        }
        catch (Exception)
        {
            // some config will hit access rights exceptions
            // this is why we try with both LOCAL_MACHINE and CURRENT_USER
        }
    } // End Sub FixBrowserVersion_Internal 

    public static int GetBrowserVersion()
    {
        // string strKeyPath = @"HKLM\SOFTWARE\Microsoft\Internet Explorer";
        string strKeyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer";
        string[] ls = new string[] { "svcVersion", "svcUpdateVersion", "Version", "W2kVersion" };

        int maxVer = 0;
        for (int i = 0; i < ls.Length; ++i)
        {
            object objVal = Microsoft.Win32.Registry.GetValue(strKeyPath, ls[i], "0");
            string strVal = System.Convert.ToString(objVal);
            if (strVal != null)
            {
                int iPos = strVal.IndexOf('.');
                if (iPos > 0)
                    strVal = strVal.Substring(0, iPos);

                int res = 0;
                if (int.TryParse(strVal, out res))
                    maxVer = Math.Max(maxVer, res);
            } // End if (strVal != null)

        } // Next i

        return maxVer;
    } // End Function GetBrowserVersion 


}

다음과 같이 클래스 사용

WebBrowserHelper.FixBrowserVersion();
WebBrowserHelper.FixBrowserVersion("SomeAppName");
WebBrowserHelper.FixBrowserVersion("SomeAppName",intIeVer);

당신은 당신의 웹 사이트 자체로 인해이 메타 태그를 추가해야 할 수도 있습니다 Windows 10의 비교 가능성에 대한 문제에 직면 할 수 있습니다

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

즐겨 🙂


답변

MSDN 의 값 사용 :

  int BrowserVer, RegVal;

  // get the installed IE version
  using (WebBrowser Wb = new WebBrowser())
    BrowserVer = Wb.Version.Major;

  // set the appropriate IE version
  if (BrowserVer >= 11)
    RegVal = 11001;
  else if (BrowserVer == 10)
    RegVal = 10001;
  else if (BrowserVer == 9)
    RegVal = 9999;
  else if (BrowserVer == 8)
    RegVal = 8888;
  else
    RegVal = 7000;

  // set the actual key
  using (RegistryKey Key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree))
    if (Key.GetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe") == null)
      Key.SetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe", RegVal, RegistryValueKind.DWord);


답변

var appName = System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe";

using (var Key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true))
    Key.SetValue(appName, 99999, RegistryValueKind.DWord);

내가 여기서 읽은 내용에 따르면 ( WebBrowser 컨트롤 호환성 제어 :

클라이언트에서 FEATURE_BROWSER_EMULATION 문서 모드 값을 IE 버전보다 높게 설정하면 어떻게됩니까?

분명히 브라우저 컨트롤은 클라이언트에 설치된 IE 버전보다 작거나 같은 문서 모드 만 지원할 수 있습니다. FEATURE_BROWSER_EMULATION 키를 사용하면 브라우저의 배포 및 지원 버전이있는 엔터프라이즈 LOB (기간 업무) 앱에 가장 적합합니다. 클라이언트에 설치된 브라우저 버전보다 높은 버전의 브라우저 모드로 값을 설정하면 브라우저 컨트롤이 사용 가능한 가장 높은 문서 모드를 선택합니다.

가장 간단한 것은 매우 높은 십진수를 넣는 것입니다 …


답변

링크를 시도 할 수 있습니다

try
{
    var IEVAlue =  9000; // can be: 9999 , 9000, 8888, 8000, 7000
    var targetApplication = Processes.getCurrentProcessName() + ".exe";
    var localMachine = Registry.LocalMachine;
    var parentKeyLocation = @"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl";
    var keyName = "FEATURE_BROWSER_EMULATION";
    "opening up Key: {0} at {1}".info(keyName, parentKeyLocation);
    var subKey = localMachine.getOrCreateSubKey(parentKeyLocation,keyName,true);
    subKey.SetValue(targetApplication, IEVAlue,RegistryValueKind.DWord);
    return "all done, now try it on a new process".info();
}
catch(Exception ex)
{
    ex.log();
    "NOTE: you need to run this under no UAC".info();
}


답변

RegKey를 변경하는 대신 HTML 헤더에 한 줄을 넣을 수있었습니다.

<html>
    <head>
        <!-- Use lastest version of Internet Explorer -->
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

        <!-- Insert other header tags here -->
    </head>
    ...
</html>

웹 브라우저 제어 및 IE 버전 지정을 참조하십시오 .


답변

여기에 제가 일반적으로 사용하고 저를 위해 작동하는 방법이 있습니다 (32 비트 및 64 비트 응용 프로그램 모두에 대해; ie_emulation은 여기에 문서화되어있는 모든 사람이 될 수 있습니다 : 인터넷 기능 제어 (B..C), 브라우저 에뮬레이션 ).

    [STAThread]
    static void Main()
    {
        if (!mutex.WaitOne(TimeSpan.FromSeconds(2), false))
        {
            // Another application instance is running
            return;
        }
        try
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var targetApplication = Process.GetCurrentProcess().ProcessName  + ".exe";
            int ie_emulation = 10000;
            try
            {
                string tmp = Properties.Settings.Default.ie_emulation;
                ie_emulation = int.Parse(tmp);
            }
            catch { }
            SetIEVersioneKeyforWebBrowserControl(targetApplication, ie_emulation);

            m_webLoader = new FormMain();

            Application.Run(m_webLoader);
        }
        finally
        {
            mutex.ReleaseMutex();
        }
    }

    private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval)
    {
        RegistryKey Regkey = null;
        try
        {
            Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);

            // If the path is not correct or
            // if user haven't privileges to access the registry
            if (Regkey == null)
            {
                YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found");
                return;
            }

            string FindAppkey = Convert.ToString(Regkey.GetValue(appName));

            // Check if key is already present
            if (FindAppkey == "" + ieval)
            {
                YukLoggerObj.logInfoMsg("Application FEATURE_BROWSER_EMULATION already set to " + ieval);
                Regkey.Close();
                return;
            }

            // If a key is not present or different from desired, add/modify the key, key value
            Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord);

            // Check for the key after adding
            FindAppkey = Convert.ToString(Regkey.GetValue(appName));

            if (FindAppkey == "" + ieval)
                YukLoggerObj.logInfoMsg("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart");
            else
                YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION setting failed; current value is  " + ieval);
        }
        catch (Exception ex)
        {
            YukLoggerObj.logWarnMsg("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message);

        }
        finally
        {
            // Close the Registry
            if (Regkey != null)
                Regkey.Close();
        }
    }


답변

Luca의 솔루션을 구현할 수 있었지만 작동하려면 몇 가지 사항을 변경해야했습니다. 내 목표는 Windows Forms 응용 프로그램 (.NET 2.0을 대상으로 함) 용 웹 브라우저 컨트롤과 함께 D3.js를 사용하는 것이 었습니다. 그것은 지금 나를 위해 일하고 있습니다. 이것이 다른 사람을 도울 수 있기를 바랍니다.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using Microsoft.Win32;
using System.Diagnostics;

namespace ClientUI
{
    static class Program
    {
        static Mutex mutex = new System.Threading.Mutex(false, "jMutex");

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (!mutex.WaitOne(TimeSpan.FromSeconds(2), false))
            {
                // Another application instance is running
                return;
            }
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                var targetApplication = Process.GetCurrentProcess().ProcessName + ".exe";
                int ie_emulation = 11999;
                try
                {
                    string tmp = Properties.Settings.Default.ie_emulation;
                    ie_emulation = int.Parse(tmp);
                }
                catch { }
                SetIEVersioneKeyforWebBrowserControl(targetApplication, ie_emulation);

                Application.Run(new MainForm());
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }

        private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval)
        {
            RegistryKey Regkey = null;
            try
            {
                Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);

                // If the path is not correct or
                // if user doesn't have privileges to access the registry
                if (Regkey == null)
                {
                    MessageBox.Show("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found");
                    return;
                }

                string FindAppkey = Convert.ToString(Regkey.GetValue(appName));

                // Check if key is already present
                if (FindAppkey == ieval.ToString())
                {
                    MessageBox.Show("Application FEATURE_BROWSER_EMULATION already set to " + ieval);
                    Regkey.Close();
                    return;
                }

                // If key is not present or different from desired, add/modify the key , key value
                Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord);

                // Check for the key after adding
                FindAppkey = Convert.ToString(Regkey.GetValue(appName));

                if (FindAppkey == ieval.ToString())
                {
                    MessageBox.Show("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart");
                }
                else
                {
                    MessageBox.Show("Application FEATURE_BROWSER_EMULATION setting failed; current value is  " + ieval);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message);
            }
            finally
            {
                //Close the Registry
                if (Regkey != null) Regkey.Close();
            }
        }
    }
}

또한 프로젝트 설정에 11999 값으로 문자열 (ie_emulation)을 추가했습니다.이 값은 IE11 (11.0.15)에서 작동하는 것 같습니다.

다음으로, 레지스트리에 대한 액세스를 허용하기 위해 애플리케이션의 권한을 변경해야했습니다. 프로젝트에 새 항목을 추가하면됩니다 (VS2012 사용). 일반 항목에서 응용 프로그램 매니페스트 파일을 선택합니다. asInvoker에서 requireAdministrator로 레벨을 변경하십시오 (아래 참조).

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

이 글을 읽는 누군가가 웹 브라우저 컨트롤과 함께 D3.js를 사용하려는 경우, D3.json이 XmlHttpRequest를 사용하기 때문에 HTML 페이지 내의 변수 내에 저장되도록 JSON 데이터를 수정해야 할 수 있습니다 (웹 서버에서 사용하기 쉬움). 이러한 변경 사항과 위의 사항 후에 내 Windows 양식은 D3를 호출하는 로컬 HTML 파일을로드 할 수 있습니다.