如何为右键菜单Remote Control的子项添加三级级联子菜单?
解决右键菜单三级级联子菜单不显示问题
问题说明
我是编程新手,现有一段实现两级右键菜单的注册表脚本,想在Remote Control子菜单下的TightVNC Viewer项中再添加一级级联子菜单。给该项添加SubCommands键后,子菜单能生成但内容始终无法显示。
原注册表代码:
[HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl] "Icon"="D:\\Mijn Data\\Portables\\VNC Viewer\\vncviewer.exe" "MUIVerb"="Remote Control" "Position"="Top" "SubCommands"="" [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\01menu] "MUIVerb"="TightVNC Viewer" "Icon"="D:\\Mijn Data\\Portables\\TightVNCViewer\\TightVNCViewerPortable.exe" [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\01menu\command] @="D:\\Mijn Data\\Portables\\TightVNCViewer\\TightVNCViewerPortable.exe" [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\02menu] "MUIVerb"="VCN Viewer" "Icon"="D:\\Mijn Data\\Portables\\VNC Viewer\\vncviewer.exe" [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\02menu\command] @="D:\\Mijn Data\\Portables\\VNC Viewer\\vncviewer.exe"
修改后的相关代码:
[HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\01menu] "MUIVerb"="TightVNC Viewer" "Icon"="D:\\Mijn Data\\Portables\\TightVNCViewer\\TightVNCViewerPortable.exe" "SubCommands"=""
解决方案
要实现三级级联菜单,仅添加SubCommands键不够,需遵循以下规则调整:
- 当菜单项设置
SubCommands=""后,它就变成纯子菜单容器,必须删除原有的command子键(否则系统会优先将其识别为可执行命令,导致子菜单内容不加载) - 在该容器项的
Shell子键下,按照二级菜单的结构添加新的子菜单项
正确的修改示例:
; 将01menu改为子菜单容器,删除原有的command子键 [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\01menu] "MUIVerb"="TightVNC Viewer" "Icon"="D:\\Mijn Data\\Portables\\TightVNCViewer\\TightVNCViewerPortable.exe" "SubCommands"="" ; 添加第一个子菜单项:连接常用主机1 [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\01menu\Shell\01submenu] "MUIVerb"="连接常用主机1" "Icon"="D:\\Mijn Data\\Portables\\TightVNCViewer\\TightVNCViewerPortable.exe" [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\01menu\Shell\01submenu\command] @="D:\\Mijn Data\\Portables\\TightVNCViewer\\TightVNCViewerPortable.exe 192.168.1.100" ; 添加第二个子菜单项:连接常用主机2 [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\01menu\Shell\02submenu] "MUIVerb"="连接常用主机2" "Icon"="D:\\Mijn Data\\Portables\\TightVNCViewer\\TightVNCViewerPortable.exe" [HKEY_CLASSES_ROOT\Directory\Background\shell\RemoteControl\Shell\01menu\Shell\02submenu\command] @="D:\\Mijn Data\\Portables\\TightVNCViewer\\TightVNCViewerPortable.exe 192.168.1.101"
关键注意事项
- 带
SubCommands的菜单项不能同时存在command子键,二者只能选其一 - 子菜单项的命名(如01submenu、02submenu)可自定义,数字前缀会影响菜单显示顺序
- 确保所有文件路径的转义符
\\正确,且图标、可执行文件实际存在于对应路径
内容的提问来源于stack exchange,提问作者Jets
相关产品推荐
相关产品推荐

