在鼠标右键菜单中添加cmd命令; 举例使用python编写的hash脚本添加到右键菜单中
1、以下是在windows添加右键cmd命令菜单
cmd_menu.reg
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\cmd_here] @="在此处打开命令行" "Icon"="cmd.exe" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\cmd_here\command] @="\"C:\\Windows\\System32\\cmd.exe\"" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cmdPrompt] @="在此处打开命令行" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cmdPrompt\command] @="\"C:\\Windows\\System32\\cmd.exe\" \"cd %1\"" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\cmd_here] @="在此处打开命令行" "Icon"="cmd.exe" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\cmd_here\command] @="\"C:\\Windows\\System32\\cmd.exe\""
2、现在我们使用Python做一个文件hash值计算的脚本,添加到鼠标右键菜单中
先安装python执行环境
在c盘tools目录下创建以下文件,
file_hash.py
import hashlib, sys, time
if __name__ == '__main__':
if len(sys.argv) != 2:
print('...没有文件路径参数.')
time.sleep(1)
sys.exit(1)
file_path = sys.argv[1]
md5_hash = hashlib.md5()
file_data = open(file=file_path, mode='rb').read()
md5_hash.update(file_data)
sha1_hash = hashlib.sha1()
sha1_hash.update(file_data)
sha256_hash = hashlib.sha256()
sha256_hash.update(file_data)
print('...md5 hash:', md5_hash.digest().hex())
print('...sha1 hash:', sha1_hash.digest().hex())
print('...sha256 hash:', sha256_hash.digest().hex())
print('...10s后自动关闭.')
time.sleep(10)
file_hash_cmd.bat
python C:/tools/file_hash.py %*
file_hash_cmd.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\file_hash\command]
@="C:\\tools\\file_hash_cmd.bat \"%1\""
导入注册表配置即可:file_hash_cmd.reg
文件打包下载: tools.zip
bat脚本中 %0 -%9表示命令行参数,%0表示bat文件名本身,%1-%9表示其后的参数
发布时间:2022-01-01 14:14:51
关键词:windows,自定义菜单
浏览量:0