... isn't easy.
@echo off&(for /f "tokens=*" %%a in ('certutil -hashfile "%1" MD5') do echo %%a&for /f "delims=" %%b in ('echo %%a^|findstr /r /i /x [0-9A-F]*') do if "%%b" neq "" echo %%b|clip&pause&exit)&pause
PowerShell is slow to load so I used batch instead. I use this command to extend the context menu of windows explorer, hence a single line.
There is one minor issue; certutil
doesn't support empty files.
Bonus registry entries: https://paste.ee/p/sgSJY
-
\$\begingroup\$ Why not put in multiple lines? Programs associated with file types can be arbitrarily long, as long as the invocation is single line. \$\endgroup\$Alejandro– Alejandro2018年02月21日 18:27:07 +00:00Commented Feb 21, 2018 at 18:27
1 Answer 1
All zero-sized files will have the same checksum using the same given hash algorithm. Hence, use the following batch-script:
@ECHO OFF
SETLOCAL EnableExtensions
for /f %%G in ("%~1") do set "_len=%%~zG"
if %_len% EQU 0 (
echo MD5 hash of %1
echo D41D8CD98F00B204E9800998ECF8427E
echo CertUtil bypassed for zero file size
echo D41D8CD98F00B204E9800998ECF8427E|clip
) else (
for /f "tokens=*" %%a in ('certutil -hashfile "%~1" MD5') do (
echo %%a
for /f "delims=" %%b in ('echo %%a^|findstr /r /i /x ^[0-9A-F]*[0-9A-F]$') do (
if "%%b" neq "" echo %%b|clip
)
)
)
pause
Note that %%~zG
expands %%G
to size of file (read call /?
).
if "%%b" neq "" echo %%b|clip
seems to be superfluous then. Simple echo %%b|clip
should suffice.
Sample output:
==> D:\bat\CodeReview179105円.bat out.txt
MD5 hash of out.txt
D41D8CD98F00B204E9800998ECF8427E
CertUtil bypassed for zero file size
Press any key to continue . . .
==> D:\bat\CodeReview179105円.bat D:\bat\CodeReview179105円.bat
MD5 hash of D:\bat\CodeReview179105円.bat:
c2a4cabffac79a26ee5ed7c97cefb44b
CertUtil: -hashfile command completed successfully.
Press any key to continue . . .
==>