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

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

检查证书吊销

/// <summary>
/// 检查证书是否吊销
/// </summary>
/// <param name="isOpen"></param>
public void SetCertificateVerificationState(bool isOpen)
{
    //检查发行商的证书是否吊销
    //0 开启,512 取消
    var softwarePublishing = @"Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing";
    RegistryHelper.ModifyCurrentUserRegistryKey(softwarePublishing, "State", isOpen ? "0" : "512 ");
    //检查服务器证书吊销
    //1开启,0关闭
    var internetSettings = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
    RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "CertificateRevocation", isOpen ? "1" : "0");
}

SSL & TSL是否勾选

/// <summary>
/// 设置SSLAndTSL
/// </summary>
/// <param name="isOpen"></param>
public void SetSSLAndTSLState(bool isOpen)
{
    //使用SSL3.0和TLS1.0
    var internetSettings = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
    RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "SecureProtocols", isOpen ? "2688" : "0");
}

修改IE安全等级

/// <summary>
/// 修改IE安全等级为中
/// </summary>
public void SetInternetProtectLevelNormal()
{ 
    //"CurrentLevel"=dword:00011000
    //"MinLevel" = dword:00011000
    //"RecommendedLevel" = dword:00011000
    var internetSettings = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3";
    RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "CurrentLevel", "00011000");
    RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "MinLevel", "00011000");
    RegistryHelper.ModifyCurrentUserRegistryKey(internetSettings, "RecommendedLevel", "00011000");
}

注册表修改:

public static bool ModifyCurrentUserRegistryKey(string registerPath, string key, string value)
{
    RegistryKey currentUserKey = null;
    RegistryKey subKey = null;
    try
    {
        currentUserKey = Registry.CurrentUser;
        subKey = GetSubKey(currentUserKey, registerPath);
        if (subKey != null)
        {
            subKey.SetValue(key, value, RegistryValueKind.DWord);
            subKey.Close();
            subKey.Dispose();
        }
    }
    catch (Exception e)
    {
        subKey?.Close();
        subKey?.Dispose();
        return false;
    }
    currentUserKey?.Close();
    currentUserKey?.Dispose();
    return true;
}
private static RegistryKey GetSubKey(RegistryKey currentUserKey, string registerPath)
{
    RegistryKey subKey;
    subKey = currentUserKey.OpenSubKey(registerPath, true);
    if (subKey == null)
    {
        subKey = currentUserKey.CreateSubKey(registerPath, RegistryKeyPermissionCheck.ReadWriteSubTree);
    }
    return subKey;
}

重置IE - 删除IE全部注册表

也可以通过删除注册表下,IE整个注册表项,来重置IE环境。

/// <summary>
/// 重置IE浏览器
/// </summary>
public void ResetInternetSetting()
{
    var internetSettings = @"Software\Microsoft\Internet Explorer";
    RegistryHelper.DeleteCurrentUserRegistryPath(internetSettings);
}
public bool DeleteCurrentUserRegistryPath(string registerPath)
{
    RegistryKey currentUserKey = null;
    try
    {
        currentUserKey = Registry.CurrentUser;
        currentUserKey.DeleteSubKey(registerPath, false);
    }
    catch (Exception e)
    {
        return false;
    }
    currentUserKey?.Close();
    currentUserKey?.Dispose();
    return true;
}

Github地址:IE环境修复工具

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main] "NoUpdateCheck"=dword:00000001 "NoJITSetup"=dword:00000001 "Start Page"="http://www.2345.com/?k542516197" "StatusBarOther"=dword:00000001 "StatusBarWeb"=dword:00000001 "Disable Script Debugger"="yes" "Show_ChannelBand"="No" "Anchor Underline"="yes" "Cache_Update_Frequency"="Once_Per_Session" "Display Inline Images"="yes" "Do404Search"=hex:01,00,00,00 "Local Page"="C:\\WINDOWS\\system32\\blank.htm" "Save_Session_History_On_Exit"="no" "Show_FullURL"="no" "Show_StatusBar"="yes" "Show_ToolBar"="yes" "Show_URLinStatusBar"="yes" "Show_URLToolBar"="yes" "Use_DlgBox_Colors"="yes" "Search Page"="http://www.microsoft.com/isapi/redir.dll?prd=ie&ar=iesearch" "XMLHTTP"=dword:00000001 "UseClearType"="yes" "Enable Browser Extensions"="yes" "Play_Background_Sounds"="yes" "Play_Animations"="yes" "CompatibilityFlags"=dword:00000000 "FullScreen"="no" "Window_Placement"=hex:2c,00,00,00,00,00,00,00,01,00,00,00,ff,ff,ff,ff,ff,ff,\ ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,00,00,00,00,00,00,00,00,00,04,00,00,e2,02,00,\ 00 "IE8RunOnceLastShown"=dword:00000001 "IE8RunOnceLastShown_TIMESTAMP"=hex:3c,3d,b1,2b,f1,e1,cf,01 "IE8RunOncePerInstallCompleted"=dword:00000001 "IE8RunOnceCompletionTime"=hex:3c,97,13,2e,f1,e1,cf,01 "IE8TourShown"=dword:00000001 "IE8TourShownTime"=hex:96,f9,15,2e,f1,e1,cf,01 "Check_Associations"="no" "AlwaysShowMenus"=dword:00000000 "Enable AutoImageResize"="YES" "NotifyDownloadComplete"="no" "DisableScriptDebuggerIE"="yes" "Friendly http errors"="yes" "Error Dlg Displayed On Every Error"="no" "IEWatsonDisabled"=dword:00000001 "ShowedCheckBrowser"="Yes" "AddToFavoritesExpanded"=dword:00000000 "window Title"="www.bzyxw.com 亿修笔记本维修中心 0543-3070132" [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Enable Browser Extensions] @="yes" [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl] [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\WindowsSearch] "Version"="WS not installed"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值