;;  
;;=====================================================================================----- 
;;  
;;FUNCTION       md5()  
;;  
;;ACTION         Returns an MD5 checksum, or verifies an MD5 checksum  
;;  
;;AUTHOR         Glenn Barnas  
;;  
;;VERSION        1.0  - 2007/07/15  
;;  
;;HISTORY        1.0  - 2007/07/15 - Initial Release 
;;  
;;SYNTAX         md5(file [,compare])  
;;  
;;PARAMETERS     file - Required - String 
;;               - Name of target file  
;; 
;;               compare - Optional - Integer 
;;               - An MD5 digest to compare against the target file  
;;  
;;REMARKS        Used to either return an MD5 checksum, or validate a file's integrity. 
;;               This would be useful in critical file-copy operations, such as 
;;               software deployments. 
;;  
;;RETURNS        digest value / boolean value 
;;               If only the filename is specified, the file's MD5 digest is returned 
;;               If the file's suspected MD5 digest is specified, a compare against 
;;               the actual digest is performed, and the UDF returns 1 on match, 0 
;;               otherwise. Exit is set by the MD5.exe - 0 on success  
;;  
;;DEPENDENCIES   md5.exe - zip file available at http://www.fourmilab.ch/md5/md5.zip  
;;  
;;TESTED WITH    W2K, WXP, W2K3  
;;  
;;EXAMPLES       $Sum = md5('here\file.exe')  
;;               Copy 'here\file.exe' 'there'  
;;               If md5('there\file.exe', $Sum)  
;;                 'Copy was successful!'  
;;               EndIf  
;  
Function MD5($File, OPTIONAL $Compare)
 
  Dim $_pCmd
 
  If $Compare = ''
    $_pCmd = CreateObject("WScript.Shell").Exec('md5.exe -n "' + $File + '"')
    $MD5 = Split($_pCmd.StdOut.ReadAll, Chr(13))[0]
  Else
    Shell '%COMSPEC% /c md5.exe -c' + $Compare + ' "' + $File + '" 2>NUL:'
    $MD5 = Not @ERROR
  EndIf
 
  Exit @ERROR
 
EndFunction