I have managed to gather code and tried to generate the hash value of a file, but in the present code I need to drag the file on the VBScript, then it gives the hash value.<
Here we go:
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oMD5: Set oMD5 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
Dim oLog 'As Scripting.TextStream
Set oArgs = WScript.Arguments
If oArgs.Count = 1 Then
sFolderPath = GetFolderPath()
Set oLog = fso.CreateTextFile(sFolderPath & "\FileHash.csv", True)
oLog.Write "sep=" & vbTab & vbCrLf
CheckFolder oArgs(I)
oLog.Close
Msgbox "Done!"
Else
Msgbox "Drop Folder"
End If
Sub CheckFolder(sFolderPath)
Dim sKey
Dim oFolder 'As Scripting.Folder
Set oFolder = fso.GetFolder(sFolderPath)
For Each oFile In oFolder.Files
oLog.Write oFile.Path & vbTab & GetMd5(oFile.Path) & vbCrLf
Next
For Each oChildFolder In oFolder.SubFolders
CheckFolder oChildFolder.Path
Next
End Sub
Function GetFolderPath()
Dim oFile 'As Scripting.File
Set oFile = fso.GetFile(WScript.ScriptFullName)
GetFolderPath = oFile.ParentFolder
End Function
Function GetMd5(filename)
Dim oXml, oElement
oMD5.ComputeHash_2(GetBinaryFile(filename))
Set oXml = CreateObject("MSXML2.DOMDocument")
Set oElement = oXml.CreateElement("tmp")
oElement.DataType = "bin.hex"
oElement.NodeTypedValue = oMD5.Hash
GetMd5 = oElement.Text
End Function
Function GetBinaryFile(filename)
Dim oStream: Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 1 'adTypeBinary
oStream.Open
oStream.LoadFromFile filename
GetBinaryFile= oStream.Read
oStream.Close
Set oStream = Nothing
End Function