IE设置,都可以通过注册表,修改。以下是一些常用的IE设置注册表修改~
检查证书吊销
1 /// <summary> 2 /// 检查证书是否吊销 3 /// </summary> 4 /// <param name="isOpen"></param> 5 public void SetCertificateVerificationState(bool isOpen) 6 { 7 //检查发行商的证书是否吊销 8 //0 开启,512 取消 9 var softwarePublishing = @"SoftwareMicrosoftWindowsCurrentVersionWinTrustTrust ProvidersSoftware Publishing"; 10 RegistryHelper.ModifyCurrentUserRegistryKey(softwarePublishing, "State", isOpen ? "0" : "512 "); 11 12 //检查服务器证书吊销 13 //1开启,0关闭 14 var internetSettings = @"SoftwareMicrosoftWindowsCurrentVersionInternet Settings"; 15 RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "CertificateRevocation", isOpen ? "1" : "0"); 16 }
SSL & TSL是否勾选
1 /// <summary> 2 /// 设置SSLAndTSL 3 /// </summary> 4 /// <param name="isOpen"></param> 5 public void SetSSLAndTSLState(bool isOpen) 6 { 7 //使用SSL3.0和TLS1.0 8 var internetSettings = @"SoftwareMicrosoftWindowsCurrentVersionInternet Settings"; 9 RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "SecureProtocols", isOpen ? "2688" : "0"); 10 }
修改IE安全等级
1 /// <summary> 2 /// 修改IE安全等级为中 3 /// </summary> 4 public void SetInternetProtectLevelNormal() 5 { 7 //"CurrentLevel"=dword:00011000 8 //"MinLevel" = dword:00011000 9 //"RecommendedLevel" = dword:00011000 10 var internetSettings = @"HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settingsones3"; 11 RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "CurrentLevel", "00011000"); 12 RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "MinLevel", "00011000"); 13 RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "RecommendedLevel", "00011000"); 14 }
注册表修改:
1 public static bool ModifyCurrentUserRegistryKey(string registerPath, string key, string value) 2 { 3 RegistryKey currentUserKey = null; 4 RegistryKey subKey = null; 5 try 6 { 7 currentUserKey = Registry.CurrentUser; 8 subKey = GetSubKey(currentUserKey, registerPath); 9 10 if (subKey != null) 11 { 12 subKey.SetValue(key, value, RegistryValueKind.DWord); 13 subKey.Close(); 14 subKey.Dispose(); 15 } 16 } 17 catch (Exception e) 18 { 19 subKey?.Close(); 20 subKey?.Dispose(); 21 return false; 22 } 23 currentUserKey?.Close(); 24 currentUserKey?.Dispose(); 25 return true; 26 } 27 28 private static RegistryKey GetSubKey(RegistryKey currentUserKey, string registerPath) 29 { 30 RegistryKey subKey; 31 subKey = currentUserKey.OpenSubKey(registerPath, true); 32 if (subKey == null) 33 { 34 subKey = currentUserKey.CreateSubKey(registerPath, RegistryKeyPermissionCheck.ReadWriteSubTree); 35 } 36 37 return subKey; 38 }
重置IE - 删除IE全部注册表
也可以通过删除注册表下,IE整个注册表项,来重置IE环境。
1 /// <summary>
2 /// 重置IE浏览器
3 /// </summary>
4 public void ResetInternetSetting()
5 {
6 var internetSettings = @"SoftwareMicrosoftInternet Explorer";
7 RegistryHelper.DeleteCurrentUserRegistryPath(internetSettings);
8 }
1 public bool DeleteCurrentUserRegistryPath(string registerPath)
2 {
3 RegistryKey currentUserKey = null;
4 try
5 {
6 currentUserKey = Registry.CurrentUser;
7 currentUserKey.DeleteSubKey(registerPath, false);
8 }
9 catch (Exception e)
10 {
11 return false;
12 }
13 currentUserKey?.Close();
14 currentUserKey?.Dispose();
15 return true;
16 }
Github地址:IE环境修复工具