Files
windows-unattend/Run-Setup.bat
Timmy 935cddbbf2 新增 steps/ 拆解版本(每段獨立 .bat 雙擊跑)+ Run-Setup.bat;端對端驗證後修 11 處 bug
steps/ 把 Setup.ps1 拆成 18 個獨立步驟(00-17),每段:
- _common.ps1 提供 Log/Section/Set-RegValue/Wait-Network helper
- 各段一個 .ps1 + 同名 .bat(自動 UAC 提權)
- _admin-shell.bat 開一個已提權 cmd,從那裡跑各 .bat 不再被 UAC 問
- RUN-ALL.bat 依序跑 00..17
- _template.bat 全部 .bat 共用樣板
- README.txt 用法說明

從 macOS WinRM 端對端跑過所有 18 段、發現並修:
- 02-rdp-enable-3389:'Remote Desktop' display group 在某些 Win11 SKU 不存在,
  改顯式 New-NetFirewallRule + Restart-Service TermService
- 04-winrm-enable:開頭加 Set-NetConnectionProfile -NetworkCategory Private fallback,
  避免 winrm quickconfig 在 Public profile 拒絕啟用
- 11-kms-activate:原本 'successful|成功' 正則在 Big5 codepage 下 mojibake 出 '{x,y}',
  改用 SoftwareLicensingProduct.LicenseStatus -eq 1 WMI 判斷
- 12-winget-install-chrome:加 --source winget,避開 msstore 憑證錯誤造成的歧義
- 13-remove-windows-ai:拿掉 -AllOptions,顯式 10 個 option 排除 UpdateCleanupCheck
  (DISM Cleanup-Image + sfc + MessageBox 在 Session-0 default Yes 觸發 Restart-Computer)
- 14-win11debloat:加 -Sysprep(寫到 Default profile 不撞 HKCU 鎖),
  從 config 移除 DisableSearchHistory/DisableSearchHighlights/HideSearchTb
  (它們的 reg.exe import 會被「存取被拒」擋住)
- 07-apply-ui-ime-default-profile:補上 IsDeviceSearchHistoryEnabled / IsDynamicSearchBoxEnabled
  替代上面從 Win11Debloat 拔掉的兩項
- 新增 00-network-private 步驟把所有 NetConnectionProfile 改 Private
- 全部 19 個 .ps1 加 UTF-8 BOM,避免 CHT Windows PS5.1 fallback ANSI 讀中文 mojibake
- 全部 .bat REM 註解改 ASCII,根除「'券蠶setup.log' 不是內部命令」那種亂碼

Run-Setup.bat:當 unattend.xml FirstLogonCommands 沒成功跑起 Setup.ps1 時,
把這支從 USB 雙擊執行,會 UAC 提權 + 從 USB 重拷 + 跑 + console 即時印 + 收 log
2026-04-28 08:35:48 +08:00

50 lines
1.5 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
REM Run-Setup.bat — 從 Ventoy USB 雙擊就能手動觸發 Setup.ps1
REM 用途:當 unattend.xml 的 FirstLogonCommands Order 5 沒成功跑起 Setup.ps1 時,
REM 把這份 .bat 從 USB 雙擊執行,會自動 UAC 提權、覆蓋 C:\Scripts\Setup.ps1、
REM 跑 Setup.ps1所有輸出含 parse error都會收到 setup-stdout.log。
setlocal
REM 先用 fltmc 偵測是否已是 Administrator不是就用 PowerShell 自我提權重啟
fltmc >nul 2>&1
if %errorLevel% neq 0 (
echo Requesting administrator privileges...
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
set "USB_DIR=%~dp0"
set "DST=C:\Scripts\Setup.ps1"
set "OUT=C:\Windows\Temp\setup-stdout.log"
echo === Run-Setup.bat (elevated) ===
echo USB source : %USB_DIR%Setup.ps1
echo Copy to : %DST%
echo Stdout log : %OUT%
echo Setup log : C:\Windows\Temp\setup.log
echo.
mkdir C:\Scripts >nul 2>&1
copy /Y "%USB_DIR%Setup.ps1" "%DST%"
if errorlevel 1 (
echo [ERROR] Copy failed. Is the USB still plugged in?
pause
exit /b 1
)
echo Running Setup.ps1 (output streams to this window AND %OUT%) ...
echo -----------------------------------------------------------------
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DST%' 2>&1 | Tee-Object -FilePath '%OUT%'"
set RC=%errorLevel%
echo -----------------------------------------------------------------
echo.
echo === Done (exit code %RC%) ===
echo View logs:
echo notepad C:\Windows\Temp\setup.log
echo notepad %OUT%
echo.
pause
endlocal