NGMsoftware

NGMsoftware
로그인 회원가입
  • 매뉴얼
  • 학습
  • 매뉴얼

    학습


    C# C#의 웹브라우저를 사용할 때 최신 버전으로 자동 설정하기.

    페이지 정보

    본문

    안녕하세요. 엔지엠소프트웨어입니다. 웹관련 프로그램을 개발할 때 C# 웹브라우저(WebBrowser) 콘트롤을 이용합니다. 개인적으로 사용하면 문제되지 않지만 범용적으로 사용하면 여러가지 문제가 발생할수도 있습니다. 요즘에는 대부분 크롬 또는 사파리를 사용하죠? 하지만, 일부 시스템은 여전히 익스플로러를 사용해야 정상 동작합니다. 그렇다보니 익스플로러가 윈도우 설치시 기본 제공되는 버전일수도 있습니다. 아래 코드는 자동으로 최신 버전으로 사용하도록 해줍니다.

    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();
        }
    }

     

    개발자에게 후원하기

    MGtdv7r.png

     

    추천, 구독, 홍보 꼭~ 부탁드립니다.

    여러분의 후원이 빠른 귀농을 가능하게 해줍니다~ 답답한 도시를 벗어나 귀농하고 싶은 개발자~

    감사합니다~

    • 네이버 공유하기
    • 페이스북 공유하기
    • 트위터 공유하기
    • 카카오스토리 공유하기
    추천1 비추천0

    댓글목록

    등록된 댓글이 없습니다.