“按任意键退出”命令提示符?

问题描述 投票:0回答:1
^!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

这是 ahk 脚本,可让您在单击任何文件并在 Windows 资源管理器中按 ctrl + shift + a 时检索 md5 哈希值。它打开命令提示符,其中包含文件路径和哈希信息。 它工作完美,但为了方便我想更进一步。

也许我想到了两件事。如果:那就太好了:

  1. 如果按下任何键,提示窗口都会关闭,而不仅仅是右上角的X按钮。
  2. 提示窗口仅显示哈希值。没有其他信息,例如“文件 ping.txt 的 MD5 哈希值:”或“CertUtil:-hashfile 命令已成功完成”。诸如此类的事情。

所以这个问题在批处理脚本和自动热键脚本中都相关。 有任何想法吗?我不懂技术。刚刚在互联网上的某个地方找到了这个脚本,我只是根据自己的喜好更改了热键。

windows batch-file cmd command-line autohotkey
1个回答
0
投票

在资源管理器或桌面中选择一个文件,然后按

Ctrl+Alt+A
获取该文件的 MD5 哈希值:

#If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class Progman") ; Explorer or Desktop

    ^!a::
        FileFullPath := Explorer_GetSelection()
        Hash := FileMD5(FileFullPath)
        MsgBox, % Hash
    return

#If 

; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=60403&p=255273#p255256
Explorer_GetSelection(){
   WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
   if !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
      Return
   shellWindows := ComObjCreate("Shell.Application").Windows
   if (winClass ~= "Progman|WorkerW")
      shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
   else {
      for window in shellWindows
       try  if (hWnd = window.HWND) && (shellFolderView := window.Document)
            break
   }
   for item in shellFolderView.SelectedItems
      result .= (result = "" ? "" : "`n") . item.Path
   if !result
      result := shellFolderView.Folder.Self.Path
   Return result
}

; https://www.autohotkey.com/board/topic/16409-md5/page-3#entry342246
FileMD5( sFile="", cSz=4 ) {
    cSz  := (cSz<0||cSz>8) ? 2**22 : 2**(18+cSz), VarSetCapacity( Buffer,cSz,0 )
    hFil := DllCall( "CreateFile", Str,sFile,UInt,0x80000000, Int,1,Int,0,Int,3,Int,0,Int,0 )
    IfLess,hFil,1, Return,hFil
    DllCall( "GetFileSizeEx", UInt,hFil, Str,Buffer ),   fSz := NumGet( Buffer,0,"Int64" )
    VarSetCapacity( MD5_CTX,104,0 ),    DllCall( "advapi32\MD5Init", Str,MD5_CTX )
    Loop % ( fSz//cSz+!!Mod(fSz,cSz) )
    DllCall( "ReadFile", UInt,hFil, Str,Buffer, UInt,cSz, UIntP,bytesRead, UInt,0 )
    , DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,Buffer, UInt,bytesRead )
    DllCall( "advapi32\MD5Final", Str,MD5_CTX ), DllCall( "CloseHandle", UInt,hFil )
    Loop % StrLen( Hex:="123456789ABCDEF0" )
    N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
    Return MD5
}
© www.soinside.com 2019 - 2024. All rights reserved.