reinstall/windows-setup.bat

43 lines
1.0 KiB
Batchfile
Raw Normal View History

2023-11-15 20:51:44 +08:00
@echo off
:: 安装 SCSI 驱动
for %%F in ("X:\drivers\*.inf") do (
:: 不要查找 Class=SCSIAdapter 因为有些驱动等号两边有空格
find /i "SCSIAdapter" "%%~F" >nul
2023-11-15 20:51:44 +08:00
if not errorlevel 1 (
drvload "%%~F"
)
)
:: 等待加载分区
:: 没有 timeout 命令
:: 没有加载网卡驱动,无法用 ping 来等待
echo wscript.sleep(5000) > sleep.vbs
cscript //nologo sleep.vbs
:: 获取主硬盘 id
for /F "tokens=2 delims==" %%A in ('wmic logicaldisk where "VolumeName='installer'" assoc:value /resultclass:Win32_DiskPartition ^| find "DiskIndex"') do (
set "DiskIndex=%%A"
)
2023-12-16 16:41:34 +08:00
:: 设置 autounattend.xml 的主硬盘 id
set "file=X:\autounattend.xml"
2023-11-15 20:51:44 +08:00
set "tempFile=X:\tmp.xml"
set "search=%%disk_id%%"
set "replace=%DiskIndex%"
(for /f "delims=" %%i in (%file%) do (
set "line=%%i"
setlocal EnableDelayedExpansion
echo !line:%search%=%replace%!
endlocal
)) > %tempFile%
move /y %tempFile% %file%
:: 执行 setup.exe
ren X:\setup.exe.disabled setup.exe
X:\setup.exe