|
::在注册表中 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
::右键新建字符串值 restore 样例: 字符串数值数据里就是填写 D:\Win7vhd\Restore_Win7vhd.cmd
@ECHO off&PUSHD %~dp0
setlocal enabledelayedexpansion
SET dif=Basevhd.vhdx
SET Sub_1=BaseSub_1.vhdx
SET Sub_2=BaseSub_2.vhdx
set ID={c16c08ed-b1b6-11ee-b734-4ccc6afb2e83}
:Start
IF NOT EXIST %~dp0!dif! call :first
for /f,"delims=",%%a in ("!dif!") do set vol=[%%~da]& set pn=%%~pa
:bcd_restore
COPY /y %~dp0!dif! %~dp0!Sub_1! >nul 2>nul
IF errorlevel 1 (
COPY /y %~dp0!dif! %~dp0!Sub_2!
BCDEDIT /set !ID! osdevice vhd=!vol!!pn!!sub_2!
BCDEDIT /set !ID! device vhd=!vol!!pn!!sub_2!
) ELSE (
BCDEDIT /set !ID! osdevice vhd=!vol!!pn!!sub_1!
BCDEDIT /set !ID! device vhd=!vol!!pn!!sub_1!
)
:reg
for /f "tokens=1*" %%c in ('bcdedit /enum !ID!') do (
if /i "%%c"=="device" (echo --BCD changed to %%d)
)
pause>nul
EXIT
:first
for /r %%d in (*.vhdx,*.vhd) do (set sys=%%~nxd)
echo %sys%& pause>nul
ECHO create vdisk file=%~dp0!dif! parent="%~dp0!sys!"|DISKPART >nul
COPY /y %~dp0!dif! %~dp0!Sub_1!
GOTO :eof
仅供参考 ... |
|