Board logo

标题: [其他] 批处理怎样调用certutil计算md5并赋值? [打印本页]

作者: 小渣飞    时间: 2019-8-27 11:30     标题: 批处理怎样调用certutil计算md5并赋值?

想把计算后的md5赋值为一个变量请问怎么做到


certutil -hashfile %0 MD5|set ...
作者: Batcher    时间: 2019-8-27 11:40

放到 for /f 命令里面
作者: h503mc    时间: 2019-8-28 17:38

本帖最后由 h503mc 于 2019-8-28 17:46 编辑

一种:
  1. @echo off
  2. ::xxxx
  3. ::xxxx
  4. call:filemd5 %0
  5. set get=%hash% %=get为文件hash=%
  6. call:textmd5 xxxxx
  7. set get=%hash% %=get为文字hash=%
  8. :textmd5
  9. echo %1 >mdt.tmp
  10. certutil -hashfile mdt.tmp MD5|find /v ":" >md5.tmp
  11. set /p hash=<md5.tmp
  12. set hash=%hash: =%
  13. del md5.tmp
  14. del mdt.tmp
  15. :filemd5
  16. certutil -hashfile %1 MD5|find /v ":" >>md5.tmp
  17. set /p hash=<md5.tmp
  18. set hash=%hash: =%
  19. del md5.tmp
  20. goto:eof
复制代码
另一种
  1. @echo off
  2. ::xxxx
  3. ::xxxx
  4. certutil -hashfile %0 MD5|find /v ":" >>md5.tmp
  5. set /p hash=<md5.tmp
  6. set hash=%hash: =%
  7. del md5.tmp
  8. ::hash结果就是变量%hash%
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2