AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1547955
Accepted
Dee Wolf
Dee Wolf
Asked: 2020-05-03 05:39:13 +0800 CST2020-05-03 05:39:13 +0800 CST 2020-05-03 05:39:13 +0800 CST

管道输出从 DIR 到 CERTUTIL

  • 772

在 Win10 中,寻找方法在命令提示符或批处理文件中通过管道将 DIR 命令的输出作为 CERTUTIL 命令的输入。IOW,我想获取与 DIR 命令匹配的所有文件的 MD5 哈希。

以下命令确实会生成E:\Temp文件夹中所有文件的裸列表:

C:\Users\RAS>dir "E:\Temp" /b

但是,当我按照以下命令进行管道传输时,会收到一条错误消息:

C:\Users\RAS>dir "E:\Temp" /b | CertUtil -hashfile %~f1 MD5
CertUtil: -hashfile command FAILED: 0x80070002 (WIN32: 2 ERROR_FILE_NOT_FOUND)
CertUtil: The system cannot find the file specified.

user1686 在Windows Vista 管道输出到 attrib 命令中的回答表明某些命令(如 ATTRIB)不将文件名作为输入,但我认为这与这里无关。

Cliff Armstrong 在获取字符串哈希并最终将其与哈希进行比较的答案看起来很有希望,但我不知道如何将每个完全限定的文件名传递给 CERTUTIL。另外,我没有使用 PowerShell 的经验,如果可能的话,我希望使用批处理文件获得解决方案。

谢谢,

德国之声

batch-file pipe
  • 1 1 个回答
  • 1781 Views

1 个回答

  • Voted
  1. Best Answer
    Io-oI
    2020-05-03T15:34:10+08:002020-05-03T15:34:10+08:00

    考虑到Dir不会将他自己的输出放在正确的参数中以供使用CertUtil,并且CertUtil不会将Dir重定向的输入放置在正确的位置(正确的位置/参数顺序)以使用它。

    如果您尝试将for /f循环与where命令一起使用,而不是dir /b(它不会导致完整的文件路径),这将导致完整的文件路径,您可以在以下位置使用输出循环变量Certutil:

    • 在命令行中:
    for /f tokens^=* %i in ('%__APPDIR__%where.exe "E:\Temp:*.*"')do @%__APPDIR__%CertUtil.exe -hashfile "%~i" MD5
    
    rem :: Output  :: 
    
    MD5 hash of E:\Temp\Turn Off LCD.exe:
    3657b64bfa767cd1ce1ea3709053ea3b
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\LngVar.exe:
    fc82a6b8fa5c24f6cbcb0f0dcbf85a2e
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\cocolor.exe:
    d9a3def8f569afda41fb6e067c5f3df3
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\aria2c.exe:
    80f598187166a8f95d86985ba0244257
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\cmdFocus.exe:
    f90f8672fa57ba4e8f0a05dec3ede654
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\where.exe:
    7b6f5b80b4db4ca0c0472625bcd0c981
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\SaveColor.exe:
    0b24aa776ca4601bb39e6e529e73e7a6
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\Windows-ISO-Downloader.exe:
    11532e016f68ef22ca96fa03020de789
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\sudoku.exe:
    a3a946be19763b72f8aab6387079207a
    CertUtil: -hashfile command completed successfully.
    • 同样在 bat/cmd 文件中:
    @echo off  
    
    for /f tokens^=* %%i in ('%__APPDIR__%where.exe "E:\Temp:*.*
    ')do %__APPDIR__%CertUtil.exe -hashfile "%%~i" MD5"
    
    rem :: Output :: 
    MD5 hash of E:\Temp\Turn Off LCD.exe:
    3657b64bfa767cd1ce1ea3709053ea3b
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\LngVar.exe:
    fc82a6b8fa5c24f6cbcb0f0dcbf85a2e
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\cocolor.exe:
    d9a3def8f569afda41fb6e067c5f3df3
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\aria2c.exe:
    80f598187166a8f95d86985ba0244257
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\cmdFocus.exe:
    f90f8672fa57ba4e8f0a05dec3ede654
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\where.exe:
    7b6f5b80b4db4ca0c0472625bcd0c981
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\SaveColor.exe:
    0b24aa776ca4601bb39e6e529e73e7a6
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\Windows-ISO-Downloader.exe:
    11532e016f68ef22ca96fa03020de789
    CertUtil: -hashfile command completed successfully.
    MD5 hash of F:\sudoku.exe:
    a3a946be19763b72f8aab6387079207a
    CertUtil: -hashfile command completed successfully.

    如果您只需要输出中的 MD5 字符串,请添加|find/v ":":

    • 在命令行中:
    @for /f tokens^=* %i in ('%__APPDIR__%where.exe "E:\Temp:*.*"')do @%__APPDIR__%CertUtil.exe -hashfile "%~i" MD5|find/v ":"
    
    rem :: Output  :: 
    
    3657b64bfa767cd1ce1ea3709053ea3b
    fc82a6b8fa5c24f6cbcb0f0dcbf85a2e
    d9a3def8f569afda41fb6e067c5f3df3
    80f598187166a8f95d86985ba0244257
    f90f8672fa57ba4e8f0a05dec3ede654
    7b6f5b80b4db4ca0c0472625bcd0c981
    0b24aa776ca4601bb39e6e529e73e7a6
    11532e016f68ef22ca96fa03020de789
    a3a946be19763b72f8aab6387079207a
    • 在 bat/cmd 文件中:
    @echo off 
    
    for /f tokens^=* %%i in ('%__APPDIR__%where.exe "E:\Temp:*.*"
    ')do %__APPDIR__%CertUtil.exe -hashfile "%%~i" MD5|find/v ":"
    
    rem :: Output  :: 
    
    3657b64bfa767cd1ce1ea3709053ea3b
    fc82a6b8fa5c24f6cbcb0f0dcbf85a2e
    d9a3def8f569afda41fb6e067c5f3df3
    80f598187166a8f95d86985ba0244257
    f90f8672fa57ba4e8f0a05dec3ede654
    7b6f5b80b4db4ca0c0472625bcd0c981
    0b24aa776ca4601bb39e6e529e73e7a6
    11532e016f68ef22ca96fa03020de789
    a3a946be19763b72f8aab6387079207a

    您还可以使用 For / r 以更简单和递归的方式执行此操作,与类似链接的问题中使用的相同:

    • 在命令行中:
    @for /r E:\temp %i in (*)do @%__APPDIR__%CertUtil.exe -hashfile "%~i" MD5|find/v ":"
    • 在 bat/cmd 文件中:
    @echo off 
    
    for /r E:\temp %%i in (*)do %__APPDIR__%CertUtil.exe -hashfile "%%~i" MD5|find/v ":"

    • 一些进一步的阅读:

      [√]哪里

      [√]哪里(PowerShell 中的 pswhere)

      [√] CertUtil

      [√] CertUtil 的更多技巧

      [√]循环

      [√]重定向

      [√] CMD/蝙蝠字符串操作

      [√] Base64 编码或解码 (MacOS/Windows/Linux)

    • 3

相关问题

  • Net Stop,如何在第一个服务“正在停止...”时停止第二个服务

  • 批量密码生成器

  • mpv:如何播放从标准输入传输的 URL 列表

  • Windows 2016 不会运行 .bat 文件

  • 如何制作批处理脚本来备份具有唯一目标文件夹的特定文件(Windows)[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve