短小精悍、绿色环保、免费开源、整洁高效
Small, Green, Freedom, Open Source, Neat, Efficient
Table of Contents
今天,开源一个批处理写的不足2k的脚本,用于计算文件的MD5值。让那些动不动就几百M或者大量写入注册表的软件汗颜去吧。
Today, I open source a cmd script that less than 2 Kb. The script is going to calculate the MD5 value of any files. Let those software that easily take hundreds of megabytes or write a large amount of data into the registry be ashamed.
功能/Features
当一个程序被修改时,它的MD5/SHA256 Hash值也会随之改变,为了保证每个人使用的文件没有被篡改过,没有感染计算机病毒,请校验MD5值,以保证使用的是干净的正版软件。
When a computer file is modified, it’s MD5/SHA256 hash value will also change accordingly. In order to ensure that the files used by everyone have not been tampered with and are not infected with computer viruses, please check the MD5 value to ensure that you are using clean and genuine software.
在数据科学上,MD5值也用作检测数据的完整性。
In data science, the MD5 value is also used to check the integrity of the data.
使用/Use
- 将需要检测MD5值的程序直接拖拽到
MD5.bat文件上。 - 或者将要检测的文件放在
MD5.bat目录下,运行MD5.bat,选择需要检测文件前面的编号。 - 在CMD窗口内,选中需要复制的文字,点鼠标右键即可完成复制。
- Drag and drop the file that needs to get the MD5 value directly onto the MD5.bat file.
- Or put the file you want to detect in the same folder as
MD5.bat, run theMD5.bat, and then select the number of the file. - In the CMD window, select the text that needs to be copied and right-click the mouse to complete the copy.
演示/Demo
拖拽方式/Drag and drop

编号方式/Numbers

下载/Download
【Github】Release v 1.0.0 · aozhangchina/md5.bat (github.com)
【链接】https://pan.baidu.com/s/1Q7aX49PMSHZPKudDbnMfkQ?pwd=yuqq 提取码:yuqq
You can use the Baidu Netdisk to download the file I have already written, which using the link previous line.
源码/Source code
软件已经开源到Github:https://github.com/aozhangchina/md5.bat
@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul
title MD5/SHA256计算工具
echo 张敖制作 https://datahold.cn
echo 把本软件放在测试文件相同的目录下运行
echo 更新 2024年2月16日
if "%~1" == "" (
@REM echo Please drag and drop a file onto this batch file.
goto n2
)
echo Dragged file information:
echo File name: %~n1
echo File extension: %~x1
echo Full path: "%~f1"
echo Directory: %~dp1
set "filename=%~f1"
echo Selected file: "%filename%"
:: Using CertUtil to calculate MD5 and SHA256 hash values for the selected file
echo Calculating MD5 and SHA256 for "%filename%"...
set "md5hash="
set "sha256hash="
for /f "tokens=* skip=1" %%a in ('CertUtil -hashfile "%filename%" MD5') do (
set "md5hash=%%a"
goto displayMD5
)
:displayMD5
echo MD5: %md5hash%
for /f "tokens=* skip=1" %%a in ('CertUtil -hashfile "%filename%" SHA256') do (
set "sha256hash=%%a"
goto displaySHA256
)
:displaySHA256
echo SHA256: %sha256hash%
goto eof
:n2
:: 初始化变量
set /a count=1
:: 列出当前目录下所有文件,并给它们编号
echo Available files:
for %%f in (*) do (
echo !count! - %%f
set "file!count!=%%f"
set /a count+=1
)
:: 获取用户输入
set /p choice="Select a file number: "
if "!choice!"=="" goto eof
:: 通过编号获取文件名
set "selectedFile=!file%choice%!"
:: 检查用户是否选择了有效编号
if "!selectedFile!"=="" (
!selectedFile! = %1
goto eof
)
:start
:: 使用CertUtil计算所选文件的MD5哈希值,并只显示MD5哈希值
echo Calculating MD5 and SHA256 for "!selectedFile!"...
for /f "tokens=* skip=1" %%a in ('CertUtil -hashfile "!selectedFile!" MD5') do (
set "md5hash=%%a"
goto displayMD52
)
:displayMD52
echo MD5: !md5hash!
:: 使用CertUtil计算所选文件的SHA256哈希值,并只显示SHA256哈希值
for /f "tokens=* skip=1" %%a in ('CertUtil -hashfile "!selectedFile!" SHA256') do (
set "sha256hash=%%a"
goto displaySHA2562
)
:displaySHA2562
echo SHA256: !sha256hash!
:eof
endlocal
echo 按任意键退出/Press any key to exit.
pause >nul
文件MD5信息/MD5 information
名称:MD5.zip
大小:1 KB
MD5:becdc41ed373485d92f575a615c8d9e0
SHA256:e38af4a446456837f4a9c4d7b83d7ce6a2671e0ce14ac48f149faed74f290bc7
如果你下载的文件MD5与我不同,请检查下载源是否安全。
If the MD5.zip has the different MD5 value, please check that the download source is secure.