热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

C#IE环境-重置IE(注册表)

IE设置,都可以通过注册表,修改。以下是一些常用的IE设置注册表修改~检查证书吊销1<summary>2检查证书是否吊销3

IE设置,都可以通过注册表,修改。以下是一些常用的IE设置注册表修改~

检查证书吊销

 1     /// 
 2     /// 检查证书是否吊销
 3     /// 
 4     /// 
 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     /// 
 2     /// 设置SSLAndTSL
 3     /// 
 4     /// 
 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     /// 
 2     /// 修改IE安全等级为中
 3     /// 
 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     }

 

注册表修改:

 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     ///  2 /// 重置IE浏览器 3 ///  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 }

 


推荐阅读
author-avatar
66顺主管386711
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有