修改注册表,这个代码好实现,关键是怎么找到对应的注册表值,也就是说画一条线很容易,难的是找到要在哪里画,然后我百度了一圈,出来的都是画线的,没有指出或者指出的不全的注册表对应值,只能翻墙谷歌了,也就有了今天这两步。

第一步:找到要设置的选项:注册表与IE设置选项对应表

第二步:根据下面code修改

IE的选项包括Activex插件相关,还有设置相关,我们项目上用到了一个ActiveX插件,但是不能让用户来设置复杂的插件设置,我们可以在安装包里添加相关的选项修改信息。

修改code如下:

using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Runtime.InteropServices; namespace ExtInstaller
{
[RunInstaller(true)]
public partial class OCXInstaller : System.Configuration.Install.Installer
{
public OCXInstaller()
{
InitializeComponent(); Trace.Listeners.Clear(); //自动清空缓冲(即时写入)
Trace.AutoFlush = true; this.AfterInstall += new InstallEventHandler(OCXInstaller_AfterInstall);
this.BeforeUninstall += new InstallEventHandler(OCXInstaller_BeforeUninstall);
} private void OCXInstaller_AfterInstall(object sender, InstallEventArgs e)
{
//获取用户设定的安装目标路径, 注意,需要在Setup项目里面自定义操作的属性栏里面的CustomActionData添加上/targetdir="[TARGETDIR]\"
string installPath = this.Context.Parameters["targetdir"];
installPath = installPath.TrimEnd('\\') + "\\"; Trace.Listeners.Add(new TextWriterTraceListener(installPath + "UnisOCX.log")); Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始安装");
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始添加环境变量: " + installPath);
//处理环境变量
string pathlist;
bool isPathExist = false; pathlist = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
string[] list = pathlist.Split(';'); foreach (string item in list)
{
if (item == installPath)
isPathExist = true;
} if (!isPathExist)
{ Environment.SetEnvironmentVariable("PATH", pathlist + ";" + installPath, EnvironmentVariableTarget.Machine);
} //添加信任站点
string strURL = "127.0.0.1"; RegistryKey hkml = Registry.CurrentUser;//读取HKEY_CURRENT_USER
string address = @"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\INTERNET SETTINGS\ZONEMAP\RANGES"; RegistryKey key1 = hkml.OpenSubKey(address, true); strURL = this.Context.Parameters["url1"];
RegistryKey Name1 = key1.CreateSubKey("Url1");//新建项 //Name1可随便改
Name1.SetValue(":Range", strURL, RegistryValueKind.String);//赋值 218.66.55.77按需求修改
Name1.SetValue("http", 0x2, RegistryValueKind.DWord);//赋值
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始添加可信站点1:" + strURL); strURL = this.Context.Parameters["url2"];
RegistryKey Name2 = key1.CreateSubKey("Url2");//新建项 //Name1可随便改
Name2.SetValue(":Range", strURL, RegistryValueKind.String);//赋值 218.66.55.77按需求修改
Name2.SetValue("http", 0x2, RegistryValueKind.DWord);//赋值
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始添加可信站点2:" + strURL); strURL = this.Context.Parameters["url3"];
RegistryKey Name3 = key1.CreateSubKey("Url3");//新建项 //Name1可随便改
Name3.SetValue(":Range", strURL, RegistryValueKind.String);//赋值 218.66.55.77按需求修改
Name3.SetValue("http", 0x2, RegistryValueKind.DWord);//赋值
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始添加可信站点3:" + strURL); strURL = this.Context.Parameters["url4"];
RegistryKey Name4 = key1.CreateSubKey("Url4");//新建项 //Name1可随便改
Name4.SetValue(":Range", strURL, RegistryValueKind.String);//赋值 218.66.55.77按需求修改
Name4.SetValue("http", 0x2, RegistryValueKind.DWord);//赋值
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始添加可信站点4:" + strURL); key1.Flush();
key1.Close(); //修改IE的安全性
//1001 下载已签名的 ActiveX 控件
//1004 下载未签名的 ActiveX 控件
//1200 运行 ActiveX 控件和插件
//1201 对没有标记为安全的 ActiveX 控件进行初始化和脚本运行
//1405 对标记为可安全执行脚本的 ActiveX 控件执行脚本
//2201 ActiveX 控件自动提示 ** Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始启用:下载已签名的 ActiveX 控件");
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始启用:下载未签名的 ActiveX 控件");
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始启用:运行 ActiveX 控件和插件");
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始启用:对没有标记为安全的 ActiveX 控件进行初始化和脚本运行");
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始启用:对标记为可安全执行脚本的 ActiveX 控件执行脚本");
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始启用:ActiveX 控件自动提示"); address = @"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\INTERNET SETTINGS\Zones";
RegistryKey key2 = hkml.OpenSubKey(address, true);
RegistryKey respect = key2.OpenSubKey("", true); respect.SetValue("", );// 3=禁用、0=启用、1=提示
respect.SetValue("", );// 3=禁用、0=启用、1=提示
respect.SetValue("", );// 3=禁用、0=启用、1=提示
respect.SetValue("", );// 3=禁用、0=启用、1=提示
respect.SetValue("", );// 3=禁用、0=启用、1=提示
respect.SetValue("", );// 3=禁用、0=启用、1=提示 key2.Flush();
key2.Close();
//设置IE退出时删除历史记录,1表示退出时删除,0表示退出时不删除
address = @"SOFTWARE\MICROSOFT\INTERNET EXPLORER\PRIVACY";
RegistryKey key3 = hkml.OpenSubKey(address, true);
key3.SetValue("ClearBrowsingHistoryOnExit", "");
key3.Flush();
key3.Close();
} //卸载程序后处理
private void OCXInstaller_BeforeUninstall(object sender, InstallEventArgs e)
{ //获取用户设定的安装目标路径, 注意,需要在Setup项目里面自定义操作的属性栏里面的CustomActionData添加上/targetdir="[TARGETDIR]\"
string installPath = this.Context.Parameters["targetdir"];
installPath = installPath.TrimEnd('\\') + "\\"; Trace.Listeners.Add(new TextWriterTraceListener(installPath + "UnisOCX.log"));
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始卸载"); //删除环境变量
string pathlist, pathAfter = ""; Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "开始删除环境变量" + installPath);
pathlist = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
string[] list = pathlist.Split(';'); foreach (string item in list)
{
if ((item != installPath) && (item.Trim() != ""))
pathAfter += item + ";";
}
pathAfter.Trim('\\');
Environment.SetEnvironmentVariable("PATH", pathAfter, EnvironmentVariableTarget.Machine); //清理注册表
}
}
}

最新文章

  1. JS 原型的妙用
  2. ubuntu下svn使用指南
  3. OC中的消息传递和初始化
  4. sourceInsight使用技巧,持续更新中~~~
  5. Python学习入门基础教程(learning Python)--5.2 Python读文件基础
  6. 1.5.7 CharFilterFactories
  7. POJ1222 高斯消元法解抑或方程
  8. mvc分层的原理
  9. setObject与setValue的区别
  10. CCF 201609-4 交通规划
  11. redis读书笔记
  12. mysql 开发基础系列17 存储过程和函数(上)
  13. LeetCode翻转矩阵后的得分-Python3<六>
  14. js如何获得局部变量的值
  15. mySQL数值类型的取值范围
  16. spring boot + session+redis解决session共享问题
  17. 【364】SVM 通过 sklearn 可视化实现
  18. C#列表所有IIS站点以及相关站点属性
  19. JAXP操作xml
  20. 微信小程序使用阿里图标

热门文章

  1. Jackson错误:Can not deserialize instance of java.lang.String out of START_OBJECT token
  2. vim 代码注释插件
  3. Flask+uwsgi+Nginx环境搭建
  4. idea 配置Spring MVC
  5. 安装SpringExt以查看schema文件
  6. C# 中 in,out,ref 的作用与区别
  7. Web应用——驾培管理系统之个人管理(作者:小圣)
  8. 云计算之路-阿里云上-阵雨:RDS故障的突袭
  9. Python 3 初探,第 2 部分: 高级主题
  10. 基于环信的仿QQ即时通讯的简单实现