|
;Windows cmd批处理脚本,一键创建/挂载/格式化/分离,VHD虚拟硬盘
@echo off
;Cacls.exe命令
;这是一个在Windows 2000/XP/Server 2003操作系统下都可以使用的命令,作用是显示或者修改文件的访问控制表,在命令中可以使用通配符指定多个文件,也可以在命令中指定多个用户。
>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
|
|