C# IE环境 - 重置IE( 注册表)
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 = @"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 }
注册表修改:
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环境修复工具
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)