You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

优化AHK脚本:实现CMD窗口按任意键关闭并仅显示MD5哈希

AHK脚本优化:简化文件MD5哈希显示并支持任意键关闭窗口

问题描述

以下是一段AHK脚本,在Windows资源管理器中选中文件后按下Ctrl+Alt+A,可获取文件MD5哈希值,但需要优化两点:

  • 命令提示符窗口支持按任意键关闭,而非仅依赖右上角关闭按钮
  • 仅显示MD5哈希值,去除额外提示文本(如“MD5 hash of file xxx:”“CertUtil: -hashfile command completed successfully.”)

原脚本代码:

^!a::
      hwnd := WinExist("A")
      for Window in ComObjCreate("Shell.Application").Windows  
          if (window.hwnd==hwnd) {
              Selection := Window.Document.SelectedItems
              for Items in Selection
                  Path_to_Selection := Items.path
          }
run %ComSpec% /k certutil -hashfile "%Path_to_Selection%" md5
return

优化后的脚本

^!a::
      hwnd := WinExist("A")
      for Window in ComObjCreate("Shell.Application").Windows  
          if (window.hwnd==hwnd) {
              Selection := Window.Document.SelectedItems
              for Items in Selection
                  Path_to_Selection := Items.path
          }
      ; 执行哈希计算、过滤冗余内容并添加任意键关闭逻辑
      run %ComSpec% /c "certutil -hashfile ""%Path_to_Selection%"" md5 | findstr /v /r ""^MD5 hash.*:$"" | findstr /v /r ""^CertUtil:.*$"" | findstr /r ""^[A-Fa-f0-9]*$"" & pause >nul"
return

优化说明

  • 过滤冗余信息:通过findstr命令精准筛选内容:
    • findstr /v /r "^MD5 hash.*:$":剔除开头为“MD5 hash of file xxx:”的提示行
    • findstr /v /r "^CertUtil:.*$":剔除开头为“CertUtil:”的状态提示行
    • findstr /r "^[A-Fa-f0-9]*$":只保留纯十六进制格式的MD5哈希值行
  • 任意键关闭窗口:添加& pause >nul,执行完命令后等待任意按键,按下后自动关闭窗口(>nul隐藏“请按任意键继续...”的多余提示)
  • 替换原脚本的/k为/c,让cmd执行完命令后自动退出,配合pause实现按任意键关闭的效果

内容的提问来源于stack exchange,提问作者medukia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 08:22:14