建立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. Python之数据类型转换

    平时我们在处理数据的时候,有些数据类型不是我们想要的,怎么办? 一.数据类型转换:要转换的类型(数据) 要把num01转换为整数:int(num01) 要把num01转换为浮点数:float(num0 ...

  2. python实现三级菜单

    一.要求: 1.一开始打印出所有省份和提示 2.用户输入省份以此查询城市 3.在按照输出的城市名提示用户输入,最后输出用户所查询的区县名 4.随时输入"back"可以返回上一级菜单 ...

  3. Codeforces 257D

    题意略. 思路:这个题目最重要的是那个不等式 a[i] <= a[i+1] <= 2 * a[i]  ,你会发现0 <= a[i+1]  -  a[i] <= a[i],令x ...

  4. nginx proxy_pass 与 rewrite 简记

    rewrite syntax: rewrite regex replacement [flag] Default: - Context: server, location, if 如果正则表达式(re ...

  5. 【重磅】PRO基础版免费,是时候和ExtJS说再见了!

    三石的新年礼物 9 年了,FineUI(开源版)终于迎来了她的继任者 - FineUIPro(基础版),并且完全免费!   FineUIPro(基础版)作为三石奉献给社区的一个礼物,绝对让你心动: 拥 ...

  6. JavaScript中基本数据类型和引用数据类型的区别

    1.基本数据类型和引用数据类型 ECMAScript包括两个不同类型的值:基本数据类型和引用数据类型. 基本数据类型指的是简单的数据段,引用数据类型指的是有多个值构成的对象. 当我们把变量赋值给一个变 ...

  7. 第II篇PCI Express体系结构概述

    虽然PCI总线取得了巨大的成功,但是随着处理器主频的不断提高,PCI总线提供的带宽愈发显得捉襟见肘.PCI总线也在不断地进行升级,其位宽和频率从最初的32位/33MHz扩展到64位/66MHz,而PC ...

  8. phpcmsv9更换模板介绍

    先分享下大概的步骤: 1.上传模版文件到服务器:2.在站点管理 里边[模板风格配置]选择新模板:3.设置不同模型对应模板:4.修改现有的栏目,匹配新模板:5.更新栏目缓存.系统缓存,更新HTML静态页 ...

  9. R语言︱函数使用技巧(循环、if族/for、switch、repeat、ifelse、stopifnot)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 后续加更内容: 应用一:if族有哪些成员呢?- ...

  10. org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException

    1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...