您的位置
主页 > 网站技术 > 语言编程 > » 正文

VBS获取文件MD5值(无组件)

来源: 站长圈 点击:

VBS获取MD5值最简单的方法是直接调用CAPICOM组件,但是由于CAPICOM组件系统并不是默认安装,所以使用起来不方便,有需要的朋友可以参考下,希望对大家有帮助!

下面这个代码不需要组件一样可以获取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




首页  - 关于站长圈  - 广告服务  - 联系我们  - 关于站长圈  - 网站地图  - 版权声明