使用Windows Installer来计算文件的MD5值

本文介绍了一个使用VBS脚本获取指定文件大小、属性、版本信息及MD5哈希值的方法。通过Windows Installer对象,脚本实现了对文件详细信息的读取,并通过自定义函数计算出文件的MD5哈希。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

' 40_FileHash.VBS
' UMU @ 22:45 2011/8/10

Option Explicit

Dim wi
Dim file
Dim file_size
DIm file_attributes
Dim file_version
Dim file_hash

Set wi = CreateObject("WindowsInstaller.Installer")
file = "D:\Program Files\Thunder Network\Thunder\Program\Thunder.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

代码来自网上,没有借助第三方API和其他工具



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值