window注册鼠标右键菜单,及子菜单

时间:2023-03-10 03:03:41
window注册鼠标右键菜单,及子菜单

最近项目中要用到c#并且要注册鼠标点击右键菜单,在这里总结了几种方法以便记录

效果图:

window注册鼠标右键菜单,及子菜单

1,reg注册,创建.reg文件,内容如下

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\disk]  (针对文件所有文件)
"MUIVerb"="云盘"
"SubCommands"="logs;addremark;searchfile" (子菜单,对应,'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\logs')
"Position"="bottom"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\logs] (子菜单)
@="查看历史记录"
"Icon"="d:\\WindowsFormsApp1.exe"(显示图片)
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\logs\command]
@="WinSshFS.exe  \"%1\" logs" (点击时调用到程序'\"%1\"和 logs'是传递到参数)

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\addremark]
@="添加备注"
"Icon"="d:\\WindowsFormsApp1.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\addremark\command]
@="WinSshFS.exe \"%1\" addremark"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\searchfile]
@="搜索文件"
"Icon"="d:\\WindowsFormsApp1.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\searchfile\command]
@="WinSshFS.exe \"%1\" searchfile"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\searchtokms]
@="知识库中搜索"
"Icon"="d:\\WindowsFormsApp1.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\searchtokms\command]
@="WinSshFS.exe search searchtokms"

[HKEY_CLASSES_ROOT\Directory\shell\disk] (针对所有文件夹)
"MUIVerb"="云盘"
"SubCommands"="logs"
"Position"="bottom"

[HKEY_CLASSES_ROOT\Directory\Background\shell\disk] (针对点击文件夹空白处)
"MUIVerb"="云盘"
"SubCommands"="searchtokms"
"Position"="bottom"

1,bat注册,其实和reg注册脚本一样.

创建.bat文件,内容如下(执行bat文件时需传递,可执行文件路径)
@echo off

set processdir=%1

if "%processdir%"=="" (exit)

set percent=%%
reg add "HKCR\*\shell\disk" /v MUIVerb /t REG_SZ /d "网盘"   /f
reg add "HKCR\*\shell\disk" /v SubCommands /d "logs;addremark;searchfile"  /f
reg add "HKCR\*\shell\disk" /v Position /d "bottom"  /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\logs" /ve /d "查看历史记录" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\logs\command" /ve /d "%processdir% \"%percent%1\" logs" /f

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\addremark" /ve /d "添加备注" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\addremark\command" /ve /d "%processdir%  \"%percent%1\" addremark" /f

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\searchfile" /ve /d "搜索文件" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\searchfile\command" /ve /d "%processdir%  \"%percent%1\" searchfile" /f

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\searchtokms" /ve /d "知识库中搜索" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\searchtokms\command" /ve /d "%processdir%  \"%percent%1\" searchtokms" /f

set directoryreg="HKCR\Directory\shell\disk"
reg add "%directoryreg%" /v MUIVerb /t REG_SZ /d "网盘"   /f
reg add "%directoryreg%" /v SubCommands /d "logs"  /f
reg add "%directoryreg%" /v Position /d "bottom"  /f

set directoryrebackgroundreg="HKCR\Directory\Background\shell\disk"
reg add "%directoryrebackgroundreg%" /v MUIVerb /t REG_SZ /d "网盘"   /f
reg add "%directoryrebackgroundreg%" /v SubCommands /d "searchtokms"  /f
reg add "%directoryrebackgroundreg%" /v Position /d "bottom"  /f