VBS 添加右键计算文件MD5的实现代码
时间:2021-02-25 10:29:46|栏目:VBS|点击: 次
最近相关的备份比较频繁,为了校验文件的完整性,老是要打开某文件HASH校验工具,比较麻烦,于是乎写了这个东东,文件较大时计算有点慢,文件的MD5值保存在剪贴板!效果如图:
Windows Registry Editor Version 5.00
Public MD5Value
MD5Sum(WScript.Arguments(0))
SetClipboardText("MD5: " & MD5Value & ", FilePath: " & WScript.Arguments(0))
Function MD5Sum(filename)
Dim MyStream, MyHashed, MD5Value
Set MyStream = CreateObject("ADODB.Stream")
MyStream.Type = 1
MyStream.Open()
MyStream.LoadFromFile(filename)
Set MyHashed = CreateObject("CAPICOM.HashedData")
MyHashed.Algorithm = 3
MyHashed.Hash(MyStream.Read())
MyStream.Close
MD5Value = MyHashed.Value
End Function
使用方法:
1.先将GetMD5.reg文件导入注册表以添加右键菜单,GetMD5.reg代码如下:
复制代码 代码如下:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\HASH(&G)\command]
@="WScript.exe //nologo c:\\windows\\system32\\GetMD5.vbs \"%1\""
2.复制GetMD5.vbs到c:\windows\system32\,即完成所有操作,GetMD5.vbs代码如下:
复制代码 代码如下:
Public MD5Value
MD5Sum(WScript.Arguments(0))
SetClipboardText("MD5: " & MD5Value & ", FilePath: " & WScript.Arguments(0))
Function MD5Sum(filename)
Dim MyStream, MyHashed, MD5Value
Set MyStream = CreateObject("ADODB.Stream")
MyStream.Type = 1
MyStream.Open()
MyStream.LoadFromFile(filename)
Set MyHashed = CreateObject("CAPICOM.HashedData")
MyHashed.Algorithm = 3
MyHashed.Hash(MyStream.Read())
MyStream.Close
MD5Value = MyHashed.Value
End Function
Sub SetClipboardText(Text)
Dim Word
Set Word = CreateObject("Word.Application")
Word.Documents.Add
Word.Selection.Text = Text
Word.Selection.Copy
Word.Quit False
End Sub
脚本如运行出错,请下载并注册CAPICOM组件
栏 目:VBS
下一篇:vbs sendKeys 16进制的结合使用(打开IE,静音,打开播放器等)
本文标题:VBS 添加右键计算文件MD5的实现代码
本文地址:http://www.codeinn.net/misctech/69528.html