… 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
    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:

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

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\CodeReview\179105.bat out.txt
MD5 hash of out.txt
CertUtil bypassed for zero file size
Press any key to continue . . .

==> D:\bat\CodeReview\179105.bat D:\bat\CodeReview\179105.bat
MD5 hash of D:\bat\CodeReview\179105.bat:
CertUtil: -hashfile command completed successfully.
Press any key to continue . . .


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.