C# IE環境 - 重置IE( 註冊表)

IE設置,均可以經過註冊表,修改。如下是一些經常使用的IE設置註冊表修改~git

檢查證書吊銷

 1     /// <summary>
 2     /// 檢查證書是否吊銷
 3     /// </summary>
 4     /// <param name="isOpen"></param>
 5     public void SetCertificateVerificationState(bool isOpen)
 6     {
 7         //檢查發行商的證書是否吊銷
 8         //0 開啓,512 取消
 9         var softwarePublishing = @"Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing";
10         RegistryHelper.ModifyCurrentUserRegistryKey(softwarePublishing, "State", isOpen ? "0" : "512 ");
11 
12         //檢查服務器證書吊銷
13         //1開啓,0關閉
14         var internetSettings = @"Software\Microsoft\Windows\CurrentVersion\Internet 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 = @"Software\Microsoft\Windows\CurrentVersion\Internet 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_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3";
11         RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "CurrentLevel", "00011000");
12         RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "MinLevel", "00011000");
13         RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "RecommendedLevel", "00011000");
14     }

 

註冊表修改:github

 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 = @"Software\Microsoft\Internet 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環境修復工具安全

相關文章
相關標籤/搜索