判断项有Active x,可信站点,阻止弹窗,每次退出清理
实现登录系统时进行判断,不满足时自动运行批处理文件修改IE设置,重启浏览器并返回登录页
————————————
//获取注册表数值数据 判断注册表Range100项是否存在 private bool IsRegeditItemExist() { string[] subkeyNames; RegistryKey hkml = Registry.CurrentUser; RegistryKey software = hkml.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges"); subkeyNames = software.GetSubKeyNames(); foreach (string keyName in subkeyNames) { if (keyName == "Range100") //判断子项 { hkml.Close(); return true; } } hkml.Close(); return false; } //获取Activex+弹窗+可信站点注册表数值数据 protected string regeditGetValue(string str, string url) { string registData; RegistryKey hkml = Registry.CurrentUser; RegistryKey software = hkml.OpenSubKey("SOFTWARE", true); RegistryKey aimdir = software.OpenSubKey(url, true); registData = aimdir.GetValue(str).ToString(); return registData; } //弹窗显示 protected bool MessageIf() { System.Windows.Forms.DialogResult dr2 = System.Windows.Forms.MessageBox.Show("将运行配置文件,运行完毕后将自动重启浏览器,是否继续", "系统异常", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning, System.Windows.Forms.MessageBoxDefaultButton.Button2, System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly); if (dr2 == System.Windows.Forms.DialogResult.OK) { return true; } else { return false; } } //运行.bat文件 private void RunBat(string batPath) { Process pro = new Process(); FileInfo file = new FileInfo(batPath); pro.StartInfo.WorkingDirectory = file.Directory.FullName; pro.StartInfo.FileName = batPath; pro.StartInfo.CreateNoWindow = false; pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; pro.Start(); pro.WaitForExit(); } //执行文件 protected void RunAndReStart() { try { //批处理文件路径以及返回的登录页面要自己设置 RunBat(@"E:\Alroy\client\IERegSet.bat"); foreach (System.Diagnostics.Process s in System.Diagnostics.Process.GetProcessesByName("iexplore")) { s.Kill(); } Thread.Sleep(1 * 1000); System.Diagnostics.Process.Start("http://localhost:4920/BZ/Login.aspx"); } catch { MessageBox.Show(this, "配置文件丢失,请联系管理员"); } }
//判断是否运行配置文件 protected void LoadJudge() { string wb = "Microsoft\\Internet Explorer\\New Windows"; string tp = "Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100"; string z3 = "Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3"; string z2 = "Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2"; string pr = "Microsoft\\Internet Explorer\\Privacy"; if (IsRegeditItemExist() == true) { //activex+可信站点+弹窗判断 if (Convert.ToInt32(regeditGetValue("ClearBrowsingHistoryOnExit",pr)) != 1 || Convert.ToInt32(regeditGetValue("CleanPassword",pr)) != 1 || Convert.ToInt32(regeditGetValue("CleanHistory", pr)) != 1 || Convert.ToInt32(regeditGetValue("CleanForms", pr)) != 1 || Convert.ToInt32(regeditGetValue("CleanDownloadHistory", pr)) != 1 || Convert.ToInt32(regeditGetValue("CleanCookies", pr)) != 1 || Convert.ToInt32(regeditGetValue("PopupMgr", wb)) != 0 || regeditGetValue(":Range", tp) != "localhost:192.168.1.118:81" || Convert.ToInt32(regeditGetValue("http", tp)) != 2 || Convert.ToInt32(regeditGetValue("120A", z2)) != 0 || Convert.ToInt32(regeditGetValue("2702", z2)) != 0 || Convert.ToInt32(regeditGetValue("120B", z2)) != 3 || Convert.ToInt32(regeditGetValue("2300", z2)) != 0 || Convert.ToInt32(regeditGetValue("2201", z2)) != 0 || Convert.ToInt32(regeditGetValue("2000", z2)) != 0 || Convert.ToInt32(regeditGetValue("1405", z2)) != 0 || Convert.ToInt32(regeditGetValue("1402", z2)) != 0 || Convert.ToInt32(regeditGetValue("1209", z2)) != 0 || Convert.ToInt32(regeditGetValue("1208", z2)) != 0 || Convert.ToInt32(regeditGetValue("1206", z2)) != 0 || Convert.ToInt32(regeditGetValue("1201", z2)) != 0 || Convert.ToInt32(regeditGetValue("1200", z2)) != 0 || Convert.ToInt32(regeditGetValue("1004", z2)) != 0 || Convert.ToInt32(regeditGetValue("1001", z2)) != 0 || Convert.ToInt32(regeditGetValue("1400", z2)) != 0 || Convert.ToInt32(regeditGetValue("2004", z2)) != 0 || Convert.ToInt32(regeditGetValue("2001", z2)) != 0 || Convert.ToInt32(regeditGetValue("1405", z3)) != 0 || Convert.ToInt32(regeditGetValue("1201", z3)) != 1 || Convert.ToInt32(regeditGetValue("1004", z3)) != 1 || Convert.ToInt32(regeditGetValue("1001", z3)) != 1 || Convert.ToInt32(regeditGetValue("1200", z3)) != 0 || Convert.ToInt32(regeditGetValue("1208", z3)) != 0 || Convert.ToInt32(regeditGetValue("2201", z3)) != 0) { if (MessageIf() == true) { RunAndReStart(); } } } else { if (MessageIf() == true) { RunAndReStart(); } } }
————————————
批处理文件:
可信站点要手动写入
@echo off &title By - CQPoyan @echo "============================" @echo " 设置可信站点" @echo " " reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range100" /v "http" /t REG_DWORD /d "00000002" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range100" /v ":Range" /t REG_SZ /d "localhost:192.168.1.118:81" /f @echo "============================" @echo " 修改ActiveX 控件和插件2" @echo " " reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "2001" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "2004" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1400" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1001" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1004" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1200" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1201" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1206" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1208" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1209" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1402" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "1405" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "2000" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "2201" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "2300" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "2702" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "120B" /t REG_DWORD /d "00000003" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "120A" /t REG_DWORD /d "00000000" /f @echo "============================" @echo " 修改ActiveX 控件和插件3" @echo " " reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v "1405" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v "1201" /t REG_DWORD /d "00000001" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v "1004" /t REG_DWORD /d "00000001" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v "1001" /t REG_DWORD /d "00000001" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v "1200" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v "1208" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v "2201" /t REG_DWORD /d "00000000" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\New Windows" /v "PopupMgr" /t REG_DWORD /d "00000000" /f @echo "============================" @echo " 修改自动清理" @echo " " reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Privacy" /v "CleanCookies" /t REG_DWORD /d "00000001" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Privacy" /v "CleanDownloadHistory" /t REG_DWORD /d "00000001" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Privacy" /v "CleanForms" /t REG_DWORD /d "00000001" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Privacy" /v "CleanHistory" /t REG_DWORD /d "00000001" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Privacy" /v "CleanPassword" /t REG_DWORD /d "00000001" /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Privacy" /v "ClearBrowsingHistoryOnExit" /t REG_DWORD /d "00000001" /f
时间: 2024-10-19 23:54:58