Search code examples
autohotkeymd5checksum

How to find the MD5 hash of a file?


Given a file with a known file path, how can you generate an MD5 hash for the file in AHK, without reimplementing the entire MD5 hashing algorithm in the code, like this post does?


Solution

  • We can use the Windows CertUtil tool to find the MD5 hash sum and Parse the output by StrSpliting it into different lines (The MD5 sum itself will be on the second line).

    cmd command used:

    CertUtil -hashfile %appdata%/appsettings/app.ini MD5
    

    (Note: replace %appdata%/appsettings/app.ini with your actual file path)


    Final Code:

    var:= ComObjCreate("WScript.Shell").Exec("cmd.exe /q /c CertUtil -hashfile %appdata%/appsettings/app.ini MD5").StdOut.ReadAll()
    MsgBox %var%
    outputArr := (StrSplit(var , "`r`n"))
    out:=outputArr[2]
    MsgBox %out%
    

    It is tested for Windows 10, although it should work for some older versions as well.