Consider that Dir
will not put his own output in the correct argument for using CertUtil
and, CertUtil
will not place Dir
redirected input in the right place (correct position/argument order) to use it.
If you try to use the for /f
loop with the where
command, instead of dir /b
(it does not result in the full file path), this will result in the full file path and you can use the output loop variable in 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.
- The same in bat/cmd file:
@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.
If you only need the MD5 strings in output, add |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
@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
You also can do it more simple and recursively using For / r, same used in like linked question:
@for /r E:\temp %i in (*)do @%__APPDIR__%CertUtil.exe -hashfile "%~i" MD5|find/v ":"
@echo off
for /r E:\temp %%i in (*)do %__APPDIR__%CertUtil.exe -hashfile "%%~i" MD5|find/v ":"