Windows cmd批处理脚本,一键创建/挂载/格式化/分离,VHD虚拟硬盘

  • Windows cmd批处理脚本,一键创建/挂载/格式化/分离,VHD虚拟硬盘已关闭评论
  • 528 views
  • A+
所属分类:Win
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
if exist %tmp%\vhdconf (del /f /q %tmp%\vhdconf)
title Www.ZhiQiang.Name
mode con: cols=45 lines=10
color 2F
pushd "%~dp0"
for /f "delims=" %%i in ('dir /b %~dp0^|findstr ".*\.vhd"') do (set name=%%i)
:menu
cls
echo.
echo 1.挂载 %name%
echo.
echo 2.分离 %name%
echo.
echo 3.创建 VHD
echo.
echo 4.格式化 %name%
echo.
choice /C:1234 /N /M "请输入你的选择[1,2,3,4]":
if errorlevel 4 goto:vhdformat
if errorlevel 3 goto:vhdadd
if errorlevel 2 goto:vhdoff
if errorlevel 1 goto:vhdon
:vhdon
echo SELECT VDISK FILE= "%~dp0%name%" >%tmp%\vhdconf
echo ATTACH VDISK NOERR >>%tmp%\vhdconf
echo LIST DISK >>%tmp%\vhdconf
DISKPART /s %tmp%\vhdconf > nul
exit
:vhdoff
echo SELECT VDISK FILE= "%~dp0%name%" >%tmp%\vhdconf
echo ATTACH VDISK NOERR >>%tmp%\vhdconf
echo DETACH VDISK >>%tmp%\vhdconf
echo LIST DISK >>%tmp%\vhdconf
DISKPART /s %tmp%\vhdconf > nul
exit
:vhdadd
cls
echo.
echo 自定义vhd虚拟硬盘文件名称与大小,按回车
echo.
set /p newname=文件名:
echo.
set /p value=大小(G):
set /a mx = (value)*(1024)
echo CREATE VDISK FILE="%~dp0%newname%.vhd" TYPE=FIXED MAXIMUM=%mx% >>%tmp%\vhdconf
echo SELECT VDISK FILE="%~dp0%newname%.vhd" >>%tmp%\vhdconf
echo ATTACH VDISK NOERR >>%tmp%\vhdconf
echo CLEAN >>%tmp%\vhdconf
echo CREATE PARTITION PRIMARY >>%tmp%\vhdconf
echo FORMAT FS=NTFS QUICK >>%tmp%\vhdconf
echo ASSIGN >>%tmp%\vhdconf
DISKPART /s %tmp%\vhdconf > nul
exit
:vhdformat
echo SELECT VDISK FILE="%~dp0%name%" >>%tmp%\vhdconf
echo ATTACH VDISK NOERR >>%tmp%\vhdconf
echo CLEAN >>%tmp%\vhdconf
echo CREATE PARTITION PRIMARY >>%tmp%\vhdconf
echo FORMAT FS=NTFS QUICK >>%tmp%\vhdconf
echo ASSIGN >>%tmp%\vhdconf
DISKPART /s %tmp%\vhdconf > nul
exit
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin