下面這個代碼不需要組件一樣可以獲取MD5值。
復制代碼 代碼如下:
Option Explicit
Dim wi
Dim file
Dim file_size
Dim file_attributes
Dim file_version
Dim file_hash
Set wi = CreateObject("WindowsInstaller.Installer")
file = "111.exe"
file_size = wi.FileSize(file)
file_attributes = wi.FileAttributes(file)
file_version = wi.FileVersion(file)
file_hash = GetFileHash(file)
Set wi = Nothing
MsgBox "File: " file vbCrLf _
"Size: " file_size vbCrLf _
"Attributes: " file_attributes vbCrLf _
"Version: " file_version vbCrLf _
"MD5: " file_hash
Function GetFileHash(file_name)
Dim file_hash
Dim hash_value
Dim i
Set file_hash = wi.FileHash(file_name, 0)
hash_value = ""
For i = 1 To file_hash.FieldCount
hash_value = hash_value BigEndianHex(file_hash.IntegerData(i))
Next
GetFileHash = hash_value
Set file_hash = Nothing
End Function
Function BigEndianHex(Int)
Dim result
Dim b1, b2, b3, b4
result = Hex(Int)
b1 = Mid(result, 7, 2)
b2 = Mid(result, 5, 2)
b3 = Mid(result, 3, 2)
b4 = Mid(result, 1, 2)
BigEndianHex = b1 b2 b3 b4
End Function
您可能感興趣的文章:- VBS 添加右鍵計算文件MD5的實現(xiàn)代碼
- VBS中通過調(diào)用CAPICOM對象實現(xiàn)SHA1MD5加密
- 用VBS實現(xiàn)PHP的md5_file函數(shù)代碼
- VBS MD5加密算法代碼
- 一段提取用戶名和md5的vbs代碼