VBS 添加右键计算文件MD5的实现代码
程序员文章站
2022-07-06 12:58:18
最近相关的备份比较频繁,为了校验文件的完整性,老是要打开某文件hash校验工具,比较麻烦,于是乎写了这个东东,文件较大时计算有点慢,文件的md5值保存在剪贴板!效果如图:...
最近相关的备份比较频繁,为了校验文件的完整性,老是要打开某文件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组件