之前开发了一个activex项目,基于ie8的,大家都知道页面嵌入activex插件会引起浏览器安全性检测问题,为了确保插件能在浏览器上正常工作,通常我们必须修改ie的安全设置,我对客户的建议是将要访问的web页面地址添加的可信任站点,然后修改可信任站点的ie安全性,也就是跟activex设置有关的都设置成开启。如下图:
但是话说客户很懒很懒,希望能够打开页面的时候就会自动的修改这个设置,悲催的需求,虽然不是很难,但是这个功能不算钱,赔了老板又搭上老板娘啊!!!
无奈,查了一些资料,总结一下,有两种方法搞定这个需求,1是通过js修改,2是通过在插件中c#语言修改:
1.js代码
<SCRIPT LANGUAGE="JavaScript">
<!--
var WshShell=new ActiveXObject("WScript.Shell");
//var str=WshShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\:Range");
//if(str=="192.168.1.148")
//alert("已经添加为受信站点");
//else
//{
//添加信任站点ip
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\","");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\http","2","REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\:Range","192.168.1.148");
//修改activex设置0为启用
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1001","0","REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1004","0","REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1200","0","REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1201","0","REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\1405","0","REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2\\2201","0","REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Internet Explorer\\New Windows\\PopupMgr","no");
//禁用xinxp弹出窗口阻止程序
alert("active控件安全设置,弹出窗口设置,设置成功");
//}
//-->
</SCRIPT>
解释一下相关的注册表键值:
下面几个是activex设置的编号
//1001 下载已签名的 ActiveX 控件
//1004 下载未签名的 ActiveX 控件
//1200 运行 ActiveX 控件和插件
//1201 对没有标记为安全的 ActiveX 控件进行初始化和脚本运行
//1405 对标记为可安全执行脚本的 ActiveX 控件执行脚本
//2201 ActiveX 控件自动提示 **
下面0到3代表的是activex设置的级别
// 3=禁用、0=启用、1=提示
2. c#语言的修改activex代码
引用命名空间:using Microsoft.Win32;
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SoftWare", true);
RegistryKey micr = key.OpenSubKey("Microsoft", true);
RegistryKey win = micr.OpenSubKey("windows", true);
RegistryKey cur = win.OpenSubKey("CurrentVersion", true);
RegistryKey inter = cur.OpenSubKey("Internet Settings", true);
RegistryKey zone = inter.OpenSubKey("ZoneMap", true);
RegistryKey rang = zone.OpenSubKey("Ranges",true);
RegistryKey zones = inter.OpenSubKey("Zones", true);
RegistryKey respect = zones.OpenSubKey("2", true);
if (rang.OpenSubKey("Range100", true) != null)
{
RegistryKey range = rang.OpenSubKey("Range100", true);
object str = range.GetValue(":Range");
MessageBox.Show(str.ToString());
}
else
{
RegistryKey r100= rang.CreateSubKey("Range100");
r100.SetValue("http", 2);
r100.SetValue(":Range", "192.168.1.148");
}
//1001 下载已签名的 ActiveX 控件
//1004 下载未签名的 ActiveX 控件
//1200 运行 ActiveX 控件和插件
//1201 对没有标记为安全的 ActiveX 控件进行初始化和脚本运行
//1405 对标记为可安全执行脚本的 ActiveX 控件执行脚本
//2201 ActiveX 控件自动提示 **
respect.SetValue("1200", 1);// 3=禁用、0=启用、1=提示
key.Flush();
key.Close();
}
catch (System.Exception ex)
{
}
}
出现个问题!!!设置完浏览器选项,要重新启动浏览器!估计客户同样懒得重启浏览器!我觉得可以有方法解决,后续跟进!!!