本帖最后由 荣耀 于 2019-9-2 13:57 编辑
你可以创建vhd虚拟硬盘,用来在虚拟机上封装windows系统
windows封装制作VHD专用脚本,简略你所有繁琐的操作。
- @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.nat.ee
- 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
复制代码
将此代码保存为.bat 即可。
当前脚本目录下,只能存在一个vhd文件。
原创,转载请注明此帖子链接!
荣耀&制作
|