马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
方式1: 通过certutil命令获取:
 - ;;;参数file --文件名
- (defun GetMD5FromFile (file / wsh res txt idx cmd)
- (setq wsh (vlax-create-object "wscript.shell"))
- (setq cmd (strcat "certutil -hashfile \"" file "\" MD5"))
- (setq res (vlax-invoke wsh 'exec cmd))
- (setq txt (vlax-invoke (vlax-get res 'stdout) 'readall))
- (setq idx (VL-STRING-POSITION (ascii "\r") txt))
- (setq txt (substr txt (+ idx 3)))
- (setq idx (VL-STRING-POSITION (ascii "\r") txt))
- (setq txt (substr txt 1 idx))
- (vlax-release-object wsh)
- txt
- )
方式2: 通过WindowsInstaller.installer类获取.
 - (defun GetMD5 (file / HASH H COUNT I S V WCS WI)
- (if
- (or
- (setq wcs (vlax-create-object "Aec32BitAppServer.AecScriptControl.1"))
- (setq wcs (vlax-create-object "ScriptControl"))
- )
- (vlax-put-property wcs "language" "VBScript")
- )
- (setq wi (vlax-create-object "WindowsInstaller.installer"))
- ;; (setq size (vlax-invoke wi 'filesize file))
- ;; (setq version (vlax-invoke wi 'fileversion file))
- (setq hash (vlax-invoke wi 'filehash file 0))
- (setq count (vlax-get-property hash 'FieldCount))
- (setq i 1)
- (setq s "")
- (repeat count
- (setq v (vlax-get-property hash 'IntegerData i))
- (setq v (rtos v 2 0))
- (setq H (vlax-invoke wcs 'eval (strcat "hex(" v ")")))
- (while (< (strlen H) 8)
- (setq H (strcat "0" H))
- )
- (setq s (strcat s
- (substr H 7 2)
- (substr H 5 2)
- (substr H 3 2)
- (substr H 1 2)
- )
- )
- (setq i (1+ i))
- )
- (vlax-release-object hash)
- (vlax-release-object wcs)
- (vlax-release-object wi)
- s
- )
用法示例:
(getMD5FromFile "c:\\temp\\test.exe")
(getMD5 "c:\\temp\\test.exe")
|