Sign in to follow this  
Followers 0
AcidCorps

FileGetMD5

2 posts in this topic

This is a script I made more for myself, I made it to learn how to read out of the CMD window and work with the response, hope you find it useful.

Requires MD5Sums.exe from md5sums-x.x.zip:

http://www.pc-tools.net/win32/md5sums/

#cs----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.8.1
    Author:         Acid Corps
    
    Script Function:
    FileGetMD5
    $s_File = File to get MD5 From
    $s_Base64 = 1 = Base64 encoded output, instead of default hex format
    0 [Default] = default hex format
    
    $MD5 = FileGetMD5('MyFile.exe', 1)
#ce ----------------------------------------------------------------------------
#include 

Func FileGetMD5($s_File, $s_Base64 = 0)
    ;Extract MD5Sums to temp dir (incase of usage from unwriteable media)
    FileInstall('md5sums.exe', @TempDir & '\md5sums.exe')
    
    ;Build command to run
    $s_Command = 'MD5Sums.exe \' 
    If $s_Base64 = 1 Then $s_Command &= ' -B' 
    $s_Command &= ' ' & $s_File
    
    ;Run Command
    $s_MD5Run = Run($s_Command, "", @SW_HIDE, $STDOUT_CHILD)
    
    ;Read Output
    $s_Line = ""
    While 1
        $s_Line &= StdoutRead($s_MD5Run)
        If @error Then ExitLoop
    WEnd
    
    ;Remove everything except for the MD5
    $s_MD5 = StringReplace(StringReplace(StringTrimRight(StringTrimLeft($s_Line, StringInStr($s_Line, $s_File, 0, -1) - 1), 20), $s_File, ''), ' ', '')
    
    ;Delete temporary MD5Sums
    FileDelete(@TempDir & '\md5sums.exe')
    
    ;Return the output
    Return $s_MD5
EndFunc   ;==>FileGetMD5

FileGetMD5.au3

md5sums.exe

Share this post


Link to post
Share on other sites



Late reply...need to figure out thie MD5 crap.

Okay. Your script...Slow...

It outputs up to 5...then kind of breaks...and stops working.

#include <Constants.au3>
MsgBox(0, "", FileGetMD5("C:\Program Files\AutoIt3\test.au3"))
Func FileGetMD5($s_File, $s_Base64 = 0)
    ConsoleWrite("1")
   ;Extract MD5Sums to temp dir (incase of usage from unwriteable media)
    FileInstall('md5sums.exe', @TempDir & '\md5sums.exe')
   ConsoleWrite("2")
   ;Build command to run
    $s_Command = 'MD5Sums.exe \'
    If $s_Base64 = 1 Then $s_Command &= ' -B'
    $s_Command &= ' ' & $s_File
   ConsoleWrite("3")
   ;Run Command
    $s_MD5Run = Run($s_Command, "", @SW_SHOW, $STDOUT_CHILD)
   ConsoleWrite("4")
   ;Read Output
    $s_Line = ""
    ConsoleWrite("5")
    While 1
        $s_Line &= StdoutRead($s_MD5Run)
        If @error Then ExitLoop
    WEnd
   ConsoleWrite("6")
   ;Remove everything except for the MD5
    $s_MD5 = StringReplace(StringReplace(StringTrimRight(StringTrimLeft($s_Line, StringInStr($s_Line, $s_File, 0, -1) - 1), 20), $s_File, ''), ' ', '')
   ConsoleWrite("7")
   ;Delete temporary MD5Sums
    FileDelete(@TempDir & '\md5sums.exe')
   ConsoleWrite("8")
   ;Return the output
    Return $s_MD5
    ConsoleWrite("9")
EndFunc  ;==>FileGetMD5

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0