建立Installer安装类,如图:

代码如下:

 using Microsoft.Win32;
using ResourceShare.UserClient.Common;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text; namespace HtmlExtractor
{
[RunInstaller(true)]
public partial class InstallerIEPlugin : System.Configuration.Install.Installer
{ private static string STRING_INTERNET_EXPLORER_MENU_EXT_NAME = "右键菜单名称(可修改)"; private static string ClassId = "DCA4FF81-B81E-4ADF-B6A8-886DEEFE3250"; public InstallerIEPlugin()
{
InitializeComponent();
} public static bool Install(string dllFullName)
{
bool result = false;
ProcessStartInfo processStartInfo = new ProcessStartInfo();
StringBuilder builder = new StringBuilder();
Win32APIsFull.GetWindowsDirectory(builder, ); processStartInfo.FileName = Path.Combine(builder.ToString(), "Microsoft.NET" + Path.DirectorySeparatorChar + "Framework" + Path.DirectorySeparatorChar + string.Format("v{0}", Environment.Version.ToString()) + Path.DirectorySeparatorChar + "RegAsm.exe");
processStartInfo.Arguments = string.Format("\"{0}\" /codebase", dllFullName);
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(processStartInfo).WaitForExit(); try
{
//为mscrollpath重新建立路径
using (RegistryKey clessids = Registry.ClassesRoot.OpenSubKey("CLSID\\{" + ClassId + "}\\InprocServer32", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
if (clessids != null)
{
clessids.SetValue("", Path.Combine(Environment.SystemDirectory, "mscoree.dll"));
}
}
//删除所有ShareyIE右键
using (RegistryKey menuExtKey = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\MenuExt", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
foreach (string subName in menuExtKey.GetSubKeyNames())
{
if (subName.Contains("Sharey"))
{
menuExtKey.DeleteSubKey(subName);
}
}
}
result = true;
}
catch (Exception ex)
{
result = false;
Logger.Debug(ex.Message + "\r\n" + ex.StackTrace);
} try
{
using (RegistryKey internetExplorerMenuExt = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\MenuExt\" + STRING_INTERNET_EXPLORER_MENU_EXT_NAME, RegistryKeyPermissionCheck.ReadWriteSubTree))
{
internetExplorerMenuExt.SetValue("", Path.Combine(Path.GetDirectoryName(dllFullName), @"IEExtractor.htm"));
internetExplorerMenuExt.SetValue("Contexts", , RegistryValueKind.DWord);
}
result = true;
}
catch (Exception ex)
{
result = false;
Logger.Debug(ex.Message + "\r\n" + ex.StackTrace);
}
return result;
} public static bool UnInstall(string dllFullName)
{
bool result = false;
try
{
Registry.CurrentUser.DeleteSubKey(@"Software\Microsoft\Internet Explorer\MenuExt\" + STRING_INTERNET_EXPLORER_MENU_EXT_NAME, false); using (RegistryKey menuExtKey = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\MenuExt", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
foreach (string subName in menuExtKey.GetSubKeyNames())
{
if (subName.Contains("Sharey"))
{
menuExtKey.DeleteSubKey(subName);
}
}
}
result = true;
}
catch (Exception ex)
{
result = false;
Logger.Debug(ex.Message + "\r\n" + ex.StackTrace);
} try
{
ProcessStartInfo processStartInfo = new ProcessStartInfo(); StringBuilder builder = new StringBuilder();
Win32APIsFull.GetWindowsDirectory(builder, ); processStartInfo.FileName = Path.Combine(builder.ToString(), "Microsoft.NET" + Path.DirectorySeparatorChar + "Framework" + Path.DirectorySeparatorChar + string.Format("v{0}", Environment.Version.ToString()) + Path.DirectorySeparatorChar + "RegAsm.exe"); processStartInfo.Arguments = string.Format(" \"{0}\" /unregister", dllFullName);
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(processStartInfo).WaitForExit();
result = true;
}
catch (Exception ex)
{
result = false;
Logger.Debug(ex.Message + "\r\n" + ex.StackTrace);
}
return result;
} public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
} public override void Commit(IDictionary savedState)
{
Install(this.Context.Parameters["assemblypath"]); base.Commit(savedState);
} public override void Rollback(IDictionary savedState)
{
UnInstall(this.Context.Parameters["assemblypath"]); base.Rollback(savedState);
} public override void Uninstall(IDictionary savedState)
{
UnInstall(this.Context.Parameters["assemblypath"]); base.Uninstall(savedState);
} public static bool IsSetuped()
{
return (Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\MenuExt\\" + STRING_INTERNET_EXPLORER_MENU_EXT_NAME, RegistryKeyPermissionCheck.ReadSubTree) != null);
}
}
}

第33行,调用了win32:的方法:

        /// <summary>
/// 获取系统安装目录
/// </summary>
/// <param name="SysDir"></param>
/// <param name="count"></param>
[DllImport("kernel32.dll")]
public static extern void GetWindowsDirectory(StringBuilder WinDir, int count);

IE浏览器右键菜单插件开发(下篇)——如何用c#安装、卸载IE右键插件的更多相关文章

  1. IE浏览器右键菜单插件开发(上篇)——自定义一个IE右键菜单项

    要做一个IE右键浏览器插件,得3步走. 第一,在IE右键菜单上添加自定义菜单名称,是通过注册表实现的,如下: string regkey = @"Software\Microsoft\Int ...

  2. 自定义右键菜单,禁用浏览器自带的右键菜单[右键菜单实现--Demo]

    许多从事Web开发的会发现有些事,我们需要禁用浏览器本事自带的右键菜单,而实现自定义的右键菜单下面我们也来实现一个自定义的右键菜单 首先来创建JSP页面 <%@ page language=&q ...

  3. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(六) 之 Layim源码改造右键菜单--好友、组管理功能的实现。

    前言 上一篇中讲解了加好友的流程,本篇将介绍好友管理,群组管理的右键菜单功能.当然由于菜单项目太多,都实现也得花费时间.只讲解一下我是如何从不知道怎么实现右键菜单到会自定义菜单的一个过程.另外呢,针对 ...

  4. 几款jQuery右键菜单插件介绍

    在网页中使用自定义右键菜单,实现上皆为使用javascript禁用浏览器默认的右键菜单,然后在网页中响应鼠标右键事件,弹出自定义的菜单. 类似右键菜单的组件网上很多.一般而言,改变浏览器的默认菜单应当 ...

  5. 怎样在Windows资源管理器中添加右键菜单以及修改右键菜单顺序

    有时,我们需要在Windows资源管理器的右键菜单中添加一些项,以方便使用某些功能或程序. 比如我的电脑上有一个免安装版的Notepad++,我想在所有文件的右键菜单中添加一项用Notepad++打开 ...

  6. jQuery右键菜单contextMenu使用实例

    在最近项目中需要频繁的右键菜单操作.我采用了contextMenu这款jQuery插件. 参考网址:http://www.jb51.net/article/58709.htm 官网demo http: ...

  7. Qt之QAbstractItemView右键菜单

    一.功能概述 说起右键菜单,之前Qt之自定义QLineEdit右键菜单这篇文章中我已经讲述过3种右键菜单的实现方式,今儿也是在啰嗦一下,针对QListWidget类在定制一下右键菜单,我使用的具体方式 ...

  8. Jquery 右键菜单(ContextMenu)插件使用记录

    目前做的项目需要在页面里面用右键菜单,在网上找到两种jquery的右键菜单插件,但是都有各种问题.所以就自己动手把两种插件结合了下. 修改后的右键菜单插架可以根据绑定的触发页面元素不同,复用同一个菜单 ...

  9. [Visual Studio] 开启Visual Studio 2012通过右键菜单创建单元测试(Unit Test)

    Visual Studio 2012可以说是迄今为止微软VS开发工具中用户体验最好的产品,无论是速度还是体验以及功能,都非常出色,但是,使用了一段时间后发现有一个之前版本VS都有的功能却在Visual ...

随机推荐

  1. linux下lampp(xampp)安装memcached扩展

    原理:根据自己的lampp中的php版本,编译memcache时,引用对应下载的php版本,并安装后的php_config来生成memcache.so文件,再将这个so文件放置到lamppp对应位置, ...

  2. python爬取快手视频 多线程下载

    就是为了兴趣才搞的这个,ok 废话不多说 直接开始. 环境: python 2.7 + win10 工具:fiddler postman 安卓模拟器 首先,打开fiddler,fiddler作为htt ...

  3. css中的关于margin-top,position和z-index的一些bug解决方案

    这两天在写一个demo的时候,就碰到一些css的问题,不知道能不能算bug,很有可能是因为我写的代码太少,孤陋寡闻了_(:зゝ∠)_.记录一下,以防下次遇到同样问题. 进入正题: 1.问题描述:div ...

  4. AVFoundation 框架初探究(四)

    叨叨两句 动手写这篇总结时候也是二月底过完年回来上班了,又开始新的一年了,今年会是什么样子?这问题可能得年底再回答自己了.在家窝了那么久,上班还是的接着看我们要看的东西,毕竟我们要做的事还真的太多的. ...

  5. POJ - 3984 bfs [kuangbin带你飞]专题一

    bfs搜索过程中将路径保存下即可. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #inc ...

  6. 项目实战14—ELK 企业内部搜索引擎

    一.els.elk 的介绍 1.els,elk els:ElasticSearch,Logstash,Kibana,Beats elk:ElasticSearch,Logstash,Kibana ① ...

  7. QRCode 扫描二维码、扫描条形码、相册获取图片后识别、生成带 Logo 二维码、支持微博微信 QQ 二维码扫描样式

    目录 功能介绍 常见问题 效果图与示例 apk Gradle 依赖 布局文件 自定义属性说明 接口说明 关于我 功能介绍 根据之前公司的产品需求,参考 barcodescanner 改的,希望能帮助到 ...

  8. DM6446的Bootloader

    RBL(ARM ROM Boot Loader)在芯片出厂的时候就已经烧写到ROM里了,这不需要大家关心,上电后,RBL会自动从EMIFA EM_CS2 memory space (0x0200 00 ...

  9. PCI、CPCI、CPCIE 区别、特点

    PCI.CPCI.CPCIE 区别.特点 CPCI总线 •PCI总线作为处理器系统的局部总线,主要目的是为了连接外部设备,而不是作为处理器的系统总线连接Cache和主存储器 •(1) PCI总线空间与 ...

  10. OkHttp使用教程——网络操作之OkHttp, Volley以及Gson

    写这篇文章的动机 在安卓项目中有一个问题可能无法避免:网络.不管你是加载图片,请求API数据还是从因特网上获得一个字节,你都是在使用网络. 鉴于网络在安卓中的重要性与基础性,当今安卓开发者面临的问题之 ...