批处理系列(15) - 右键菜单执行批处理文件
run a batch file at folder's context menu.
add a right click menu action that runs a custom batch script.
本篇无知识点,只是将前面写的,弄到右键菜单,方便随时调用。
对以前批处理代码进行调整,主要是对进入的目录参数进行调整。
这里要把一个批处理文件做两份处理:
set "HandleDir=%~1"
对应到HKEY_CLASSES_ROOT\Directory\shell\
;
set "HandleDir=%cd%"
对应到HKEY_CLASSES_ROOT\Directory\Background\
。
执行时分别为
@="cmd.exe /c C:\\bat\\dir.bat %1 \"%V\""
;
@="cmd.exe /c C:\\bat\\dir-bg.bat %cd% \"%V\""
我这里是将处理之后的批处理文件放在了C:\bat
这里不贴代码了,点击链接下载查看源码
- 文件命名操作 -
file.bat
,file-bg.bat
- 目录命名操作-
dir.bat
,dir-bg.bat
- 获取文件和目录名-
name.bat
,name-bg.bat
保存并执行下面文件和目录命名操作.reg
文件,然后在目标目录鼠标右键就可以选择相关操作项了。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\xfiles]
@="文件命名操作(&A)"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\shell\xfiles\command]
@="cmd.exe /c C:\\bat\\file.bat %1 \"%V\""
[HKEY_CLASSES_ROOT\Directory\Background\shell]
[HKEY_CLASSES_ROOT\Directory\Background\shell\xfiles]
@="文件命名操作(&A)"
[HKEY_CLASSES_ROOT\Directory\Background\shell\xfiles\command]
@="cmd.exe /c C:\\bat\\file-bg.bat %cd% \"%V\""
[HKEY_CLASSES_ROOT\Directory\shell\xdir]
@="目录命名操作(&Q)"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\shell\xdir\command]
@="cmd.exe /c C:\\bat\\dir.bat %1 \"%V\""
[HKEY_CLASSES_ROOT\Directory\Background\shell]
[HKEY_CLASSES_ROOT\Directory\Background\shell\xdir]
@="目录命名操作(&Q)"
[HKEY_CLASSES_ROOT\Directory\Background\shell\xdir\command]
@="cmd.exe /c C:\\bat\\dir-bg.bat %cd% \"%V\""
[HKEY_CLASSES_ROOT\Directory\shell\xfiledirname]
@="文件和目录名(&Z)"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\shell\xfiledirname\command]
@="cmd.exe /c C:\\bat\\name.bat %1 \"%V\""
[HKEY_CLASSES_ROOT\Directory\Background\shell]
[HKEY_CLASSES_ROOT\Directory\Background\shell\xfiledirname]
@="文件和目录名(&Z)"
[HKEY_CLASSES_ROOT\Directory\Background\shell\xfiledirname\command]
@="cmd.exe /c C:\\bat\\name-bg.bat %cd% \"%V\""
右键菜单添加命令行入口.reg
保存并执行,在任何目录即可调用cmd。此功能跟批处理没关系,可忽略。
Windows Registry Editor Version 5.00
;[-HKEY_CLASSES_ROOT\Directory\shell\xcmd]
;[-HKEY_CLASSES_ROOT\Directory\Background\shell\xcmd]
;[-HKEY_CLASSES_ROOT\Drive\shell\xcmd]
;[-HKEY_CLASSES_ROOT\LibraryFolder\background\shell\xcmd]
[HKEY_CLASSES_ROOT\Directory\shell\xcmd]
@="CLI"
[HKEY_CLASSES_ROOT\Directory\shell\xcmd\command]
@="cmd.exe /s /k pushd \"%V\""
[HKEY_CLASSES_ROOT\Drive\shell\xcmd]
@="CLI"
[HKEY_CLASSES_ROOT\Drive\shell\xcmd\command]
@="cmd.exe /s /k pushd \"%V\""
[HKEY_CLASSES_ROOT\Directory\Background\shell]
[HKEY_CLASSES_ROOT\Directory\Background\shell\xcmd]
@="CLI"
[HKEY_CLASSES_ROOT\Directory\Background\shell\xcmd\command]
@="cmd.exe /s /k pushd \"%V\""
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\xcmd]
@="CLI管理员(&X)"
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\xcmd\command]
@="cmd.exe /s /k pushd \"%V\""
;[-HKEY_CLASSES_ROOT\Directory\shell\runas]
;[-HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
;[-HKEY_CLASSES_ROOT\Drive\shell\runas]
;[-HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas]
[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="CLI管理员(&X)"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@="CLI管理员(&X)"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
[HKEY_CLASSES_ROOT\Drive\shell\runas]
@="CLI管理员(&X)"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Drive\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas]
"HasLUAShield"=""
@="CLI管理员(&X)"
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
转载保留原文地址和作者名,只为错误勘正和信息补充。
版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
如您发现有误,请联系xianghongai@gmail.com指正。