惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 小 强

小题大做之MySQL 5.0存储过程编程入门 车票,转让,杭州,武汉,2月3号[已过期] 2007即将过去,我很怀念它,2008 小强年,我很期待 附加数据库,并且迁移用户的方法 [收藏]ContentType类型大全 - 小 强 - 博客园 ASP.NET 1.1 Web Application Compilation and Pre-compilation 解决访问局域网内共享目录需要登陆的问题 [收藏]通过命令的方式调用系统的小工具 [收藏]Do All in Cmd Shell 解决文件无法上传的问题,错误信息:System.IO.DirectoryNotFoundException: Could not find a part of the path. 远程连接SQL Sever2000出错,1433端口未开放的解释 通过调用系统API获得网卡真实MAC地址 C#拖放操作获得文件名 [收藏]DOS 命令大全 查找目录下某特定后缀名的文件的简单方法 用GB2312编码写文件 [转载] Windows Forms 实现安全的多线程详解 准备看的关于多线程的文章(临时记录) C#文件重命名的方法
如何添加IE右键菜单
小 强 · 2006-04-20 · via 博客园 - 小 强

C#中在IE右键菜单中添加自定义项的方法

  1. 首先需要在增加注册表项 HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyApp
    MyApp为你想要显示在右键菜单中的名称
  2. VBScript处理脚本,新增的注册表项的默认值是包含这个VBScript脚本的Html页面地址。

具体代码如下:

添加注册表项:

/// <summary>
/// 在IE中增加右键菜单
/// </summary>

static void RegistryIeContextMenu() {
    
try {
        
string regkey = @"Software\Microsoft\Internet Explorer\MenuExt\MyApp";
        
string scriptPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "geturl.htm");
        RegistryKey root 
= Registry.CurrentUser.OpenSubKey(regkey);
        
if (null == root) {
            root 
= Registry.CurrentUser.CreateSubKey(regkey);
            root.SetValue(
"", scriptPath, RegistryValueKind.String);
            root.SetValue(
"Contexts"0x00000022, RegistryValueKind.DWord);
        }

    }
 catch (Exception ex) {
        DFApp.LogDebug(ex.ToString());
    }

}

脚本geturl.htm(我是直接在迅雷的geturl.htm基础上改的)

<script language="VBScript">

Sub AddLink(Url,Info,Location) 
    
On Error Resume Next

    
if Url <> "" then
    
if Info = "" then
        Info 
= "unknown"
    
end if
    
if Len(Info) > 1000 then
            Info 
= Left(Info, 1000)
        
end if

        DownloadInfo 
=  Url + "^" + Info
        
set shell = CreateObject("Wscript.Shell")
        
        shell.Run 
"C:\MyApp.EXE " + DownloadInfo

    
end if
end sub

Sub OnContextMenu()

    
set srcEvent = external.menuArguments.event
    
set srcLocation = external.menuArguments.location
    
set EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.clientX, srcEvent.clientY )
    
if srcEvent.type = "MenuExtAnchor" then 
        
set srcAnchor = EventElement
        
do until TypeName(srcAnchor)="HTMLAnchorElement"
            
set srcAnchor=srcAnchor.parentElement
        
Loop
        
Call AddLink(srcAnchor.href,srcAnchor.innerText,srcLocation)
    
elseif srcEvent.type="MenuExtImage" then
        
if TypeName(EventElement)="HTMLAreaElement" then
            
Call AddLink(EventElement.href,EventElement.Alt,srcLocation)
        
else 
            
set srcImage = EventElement
            
set srcAnchor = srcImage.parentElement
            
do until TypeName(srcAnchor)="HTMLAnchorElement"
                
set srcAnchor=srcAnchor.parentElement
                
if TypeName(srcAnchor)="Nothing" then 
                    
call AddLink(srcImage.href,srcImage.Alt,srcLocation)
                    
exit sub
                
end if
            
Loop
            
Call AddLink(srcAnchor.href,srcImage.Alt,srcLocation)
        
end if
    
elseif srcEvent.type="MenuExtUnknown" then
        
set srcAnchor = EventElement
        
do until TypeName(srcAnchor)="HTMLAnchorElement"
            
set srcAnchor=srcAnchor.parentElement
            
if TypeName(srcAnchor)="Nothing" then 
                
Call AddLink(EventElement.href,EventElement.innerText,srcLocation)
                
exit sub
            
end if
        
Loop
        
Call AddLink(srcAnchor.href,srcAnchor.innerText,srcLocation)
    
elseif 1=1 then
        
MsgBox("Unknown Event Source """ + srcEvent.type + """" + vbCrLf + "Please send description of error to fengliang@sandai.net")
    
end if
end sub

call OnContextMenu()

</script>

参考文档:
如何在IE右键菜单中添加菜单项