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 RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"SOFTWAREMicrosoftInternet ExplorerMainFeatureControlFEATURE_BROWSER_EMULATION", true);
// 64位的时候key为空所以重新创建一个 if (Key == null) { RegistryKey Key2 = Registry.CurrentUser.OpenSubKey (@"SOFTWAREMicrosoftInternet ExplorerMainFeatureControl", true); Key = Key2.CreateSubKey("FEATURE_BROWSER_EMULATION"); } Key.SetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe", RegVal, RegistryValueKind.DWord); Key.Close();