建立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. 【国家集训队2010】小Z的袜子[莫队算法]

    [莫队算法][国家集训队2010]小Z的袜子 Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程, ...

  2. Java基础系列--static关键字

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/8477914.html 一.概述 static关键字是Java诸多关键字中较常使用的一个,从 ...

  3. POI导出EXCEL,浏览器不兼容,文件名称乱码,文件无法打开解决方法

  4. SDK编程之多线程编程

    本课中,我们将学习如何进行多线程编程.另外我们还将学习如何在不同的线程间进行通信. 理论:前一课中,我们学习了进程,其中讲到每一个进程至少要有一个主线程.这个线程其实是进程执行的一条线索,除此主线程外 ...

  5. 用Composer获取第三方资源总是失败咋办?

    凉拌!!! 不不不,哥可是一个有追求的人,没那么容易放弃的! 所以我选择用中国全量镜像,https://pkg.phpcomposer.com/ 使用方法: 对,就是命令行方法,我最喜欢的方法!!! ...

  6. yii2自带的backend,frontend不够用,添加一个后台模块怎么做?

    在复杂项目里,高级模板中的fontend.backend application明显不够,可以再添加另外的application. 例如添加一个seller application .步骤如下: 1, ...

  7. 《android开发艺术探索》读书笔记(七)--动画

    接上篇<android开发艺术探索>读书笔记(六)--Drawable No1: 自定义动画:派生一种新动画只需要继承Animation这个抽象类,然后重写它的initialize和app ...

  8. PAT1001 A+B Format

    思路:每三位分割,注意符号,首位不要出现逗号. AC代码 #include <stdio.h> #include <algorithm> using namespace std ...

  9. POJ - 2251 bfs [kuangbin带你飞]专题一

    立体bfs,共有六个方向: const int dx[] = {0,0,1,-1,0,0}; const int dy[] = {1,-1,0,0,0,0}; const int dz[] = {0, ...

  10. ARC068E - Snuke Line

    原题链接 题意简述 给出个区间和.求对于任意,有多少个区间包含的倍数. 题解 考虑怎样的区间不包含的倍数. 对于的倍数和,满足的区间不包含任何的倍数. 于是转化为二维数点问题,可以用可持久化线段树解决 ...