Skip to content

Instantly share code, notes, and snippets.

@hui-shao
Created May 20, 2023 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hui-shao/ae616b7922bf862f471f085b594a6b75 to your computer and use it in GitHub Desktop.
Save hui-shao/ae616b7922bf862f471f085b594a6b75 to your computer and use it in GitHub Desktop.
A script helps to compact vhd/vhdx.
@echo off
if [%1]==[] (
echo ========= 使用说明=========
echo 请将文件拖放到该批处理上。
echo 按任意键退出...
pause>nul
exit /B 1
) else (
del /q DiskPart_compact_temp >nul 2>nul
echo select vdisk file="%1">>DiskPart_compact_temp
echo detach vdisk>>DiskPart_compact_temp
echo attach vdisk readonly>>DiskPart_compact_temp
echo compact vdisk>>DiskPart_compact_temp
echo detach vdisk>>DiskPart_compact_temp
echo attach vdisk>>DiskPart_compact_temp
start /wait diskpart /s DiskPart_compact_temp
del DiskPart_compact_temp
echo 运行完成,按任意键退出。
pause>nul
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment