using System.Runtime.InteropServices; using Microsoft.Win32;
레지스트리에 세팅하고 값이 정상적인지 체크하도록 하는 함수 입니다.
private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval) { string RegKeyPath = ""; RegistryKey Regkey = null; try { // x86, x64 구분 if (Environment.Is64BitProcess) { RegKeyPath = @"SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; } else { RegKeyPath = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; } // try { Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(RegKeyPath, true); } catch (Exception ex) { Console.WriteLine(" 관리자 권한이 아니여서 접근이 불가능 합니다."); } finally { // 레지스트리의 값을 체크 if (Regkey == null) { // 찾지 못할 경우 그냥 PASS } else { // 실행 프로세스가 등록되어 있는지 값을 가져오기 string FindAppkey = Convert.ToString(Regkey.GetValue(appName)); // 이미 세팅 되어 있을 경우 if (FindAppkey == ieval.ToString()) { Regkey.Close(); } else { // 값 세팅하기 Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord); //check for the key after adding FindAppkey = Convert.ToString(Regkey.GetValue(appName)); if (FindAppkey != ieval.ToString()) { Console.WriteLine("IE 에뮬레이트 값을 설정하지 못하엿습니다."); } } } } } catch (Exception ex) { } finally { //레지스트리 수정을 종료함. if (Regkey != null) { Regkey.Close(); } } }
프로그램 시작전에 체크헤서 체크 하도록 합니다.
Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // 현재 프로세스 이름 획득 var targetApplication = System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe"; int browserver = 7; int ie_emulation = 11999; // 설치된 브라우저 버전 체크 using (WebBrowser wb = new WebBrowser()) { browserver = wb.Version.Major; if (browserver >= 11) { ie_emulation = 11001; } else if (browserver == 10) { ie_emulation = 10001; } else if (browserver == 9) { ie_emulation = 9999; } else if (browserver == 8) { ie_emulation = 8888; } else { ie_emulation = 7000; } } // 레지스트리에 값 세팅 SetIEVersioneKeyforWebBrowserControl(targetApplication, ie_emulation); // 프로그램 시작 Application.Run(new MainForm());