由于是纯文本格式,明码无欺,不会篡改主页什么的,绝对安全!而且可以自己随意修改。
作为批处理脚本,为了这个小目标,这个已经写得够复杂了,但功能也够傻瓜(支持一键按到底),同时也够灵活(可单独执行其中某一项功能)。
这可能是世界上最小且功能相对齐全的系统安装器了!
请自行保存到记事本,保存为扩展名为cmd的文件,即可在PE环境使用。
@echo off
setlocal enabledelayedexpansion
color 1f
mode con: cols=80 lines=33
title Windows系统部署工具 - 深山红叶
:: 设置工作目录及全局变量存储文件
:: 清理可能的残留
set "WORK_DIR=%temp%\WinDeploy"
set "GLOBAL_VARS=%WORK_DIR%\global_vars.txt"
if not exist "%WORK_DIR%" mkdir "%WORK_DIR%"
del "%WORK_DIR%\*.txt" >nul 2>&1
:: 初始化全局变量存储文件
if not exist "!GLOBAL_VARS!" (echo. > "!GLOBAL_VARS!")
:: 加载全局变量(关键:跨菜单共享变量)
call :load_global_vars
:: 主程序入口
:main_menu
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ ║
echo ║ Windows系统部署工具(PE环境专用) ║
echo ║ ║
echo ║ 深山红叶 ║
echo ║ ║
echo ╠══════════════════════════════════════════════════╣
echo ║ 1. 一键安装(包含下面所有步骤) ║
echo ╠══════════════════════════════════════════════════╣
echo ║ 2. 展开 Windows 系统映像文件到硬盘 ║
echo ║ ║
echo ║ 3. 植入无人值守文件到目标系统 ║
echo ║ ║
echo ║ 4. 修复目标系统 EFI 引导 ║
echo ║ ║
echo ║ 5. 退出工具 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ ║
echo ║ 【注意】 ║
echo ║ ║
echo ║ 务必事先做好硬盘的分区准备! ║
echo ║ 务必在操作前请备份重要数据! ║
echo ║ 本工具将引导您完成 Windows 安装部署。 ║
echo ║ ║
echo ╚══════════════════════════════════════════════════╝
echo.
set /p choice=. 请选择操作(1-5):
if "%choice%"=="1" (
call :deploy_system
if errorlevel 1 goto main_menu
call :deploy_unattend
if errorlevel 1 goto main_menu
call :repair_uefi
goto main_menu
)
if "%choice%"=="2" (
call :deploy_system
goto main_menu
)
if "%choice%"=="3" (
call :deploy_unattend
goto main_menu
)
if "%choice%"=="4" (
call :repair_uefi
goto main_menu
)
if "%choice%"=="5" goto exit_tool
echo.
echo 【错误】选择无效,请重新输入!
pause >nul
goto main_menu
:: 部署Windows系统
:deploy_system
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 第一步:确认安装源 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ 请挂载Windows安装映像到虚拟光驱或展开到U盘。 ║
echo ║ 然后确认Windows安装源文件位置: ║
echo ║ 通常位于安装U盘或ISO挂载盘的sources目录下 ║
echo ║ 文件名应为install.wim或install.esd ║
echo ╚══════════════════════════════════════════════════╝
echo.
:input_source
echo.
set /p drive_letter=. 请输入安装文件所在的盘符(例如 F,不要冒号):
if "%drive_letter%"=="" (
echo 【错误】盘符不能为空!
goto input_source
)
set "drive_letter=%drive_letter::=%"
set "wim_path=%drive_letter%:\sources\install.wim"
set "esd_path=%drive_letter%:\sources\install.esd"
if exist "%wim_path%" (
set "source_path=%wim_path%"
echo.
echo 找到 install.wim 文件:%wim_path%
) else if exist "%esd_path%" (
set "source_path=%esd_path%"
echo.
echo 找到 install.esd 文件:%esd_path%
) else (
echo 【错误】%drive_letter%:\sources\ 目录找不到 install.wim 或 install.esd 文件!
pause >nul
goto input_source
)
echo.
echo [√] 安装源文件确认成功:%source_path%
echo.
echo 任意键继续……
set "GLOBAL_SOURCE_PATH=%source_path%"
call :save_global_vars :: 保存变量到文件
pause >nul
:select_target
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 第二步:选择目标磁盘 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ 即将展示所有磁盘列表。 ║
echo ║ 请选择要安装Windows的目标磁盘。 ║
echo ║ 【警告】目标磁盘的数据将被覆盖! ║
echo ╚══════════════════════════════════════════════════╝
cls
echo.
echo.
echo 当前计算机磁盘列表
echo ========================================================
echo list disk > "%WORK_DIR%\list_disk.txt"
diskpart /s "%WORK_DIR%\list_disk.txt"
del "%WORK_DIR%\list_disk.txt" >nul 2>&1
echo.
echo 请根据磁盘容量信息确定要安装的目标磁盘。
:input_target_disk
echo.
set /p target_disk= 请输入目标磁盘编号(例如0):
if "%target_disk%"=="" (
echo 【错误】输入不能为空!
goto input_target_disk
)
cls
echo.
echo.
echo 所选目标磁盘分区列表
echo ========================================================
echo.
echo select disk %target_disk% > "%WORK_DIR%\list_part.txt"
echo list partition >> "%WORK_DIR%\list_part.txt"
diskpart /s "%WORK_DIR%\list_part.txt"
del "%WORK_DIR%\list_part.txt" >nul 2>&1
echo.
set /p target_partition= 请输入目标分区编号(例如 2 ):
if "%target_partition%"=="" (
echo.
echo 【错误】输入不能为空!
goto input_target_disk
)
set "temp_drive=X"
echo select disk %target_disk% > "%WORK_DIR%\assign_temp.txt"
echo select partition %target_partition% >> "%WORK_DIR%\assign_temp.txt"
echo assign letter=%temp_drive% >> "%WORK_DIR%\assign_temp.txt"
echo exit >> "%WORK_DIR%\assign_temp.txt"
diskpart /s "%WORK_DIR%\assign_temp.txt" >nul 2>&1
if not exist "%temp_drive%:\" (
echo.
echo 【错误】无法访问目标分区!
pause >nul
goto input_target_disk
)
:: 保存目标磁盘/分区/盘符到全局变量
set "GLOBAL_TARGET_DRIVE=%temp_drive%"
set "GLOBAL_TARGET_DISK=%target_disk%"
set "GLOBAL_TARGET_PARTITION=%target_partition%"
call :save_global_vars :: 持久化保存
echo [√] 目标分区:磁盘%target_disk% 分区%target_partition% (%temp_drive%:),确认后请按任意键继续!
echo.
pause >nul
:select_image
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 第三步:选择系统版本 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ ║
echo ║ 正在获取映像信息... ║
echo ║ ║
echo ╚══════════════════════════════════════════════════╝
echo.
dism /Get-ImageInfo /ImageFile:"%GLOBAL_SOURCE_PATH%" > "%WORK_DIR%\image_info.txt" 2>&1
findstr /c:"索引:" "%WORK_DIR%\image_info.txt" >nul
if errorlevel 1 (
echo 【错误】无法读取映像文件!
pause >nul
goto select_image
)
echo.
echo 可用的 Windows 版本
echo ==================================================
echo.
set "inputFile=%WORK_DIR%\image_info.txt"
set "outputFile=%WORK_DIR%\out.txt"
del /q "%outputFile%" 2>nul
set "prevLine="
for /f "delims=" %%a in ("%inputFile%") do (
set "currentLine=%%a"
if "!currentLine:~0,4!"=="索引" (
set "prevLine=!currentLine!"
) else if "!currentLine:~0,5!"=="Index" (
set "prevLine=!currentLine!"
) else if "!currentLine:~0,4!"=="名称" (
:: 保留“名称”行时不修改prevLine
) else if "!currentLine:~0,4!"=="Name" (
:: 保留“Name”行时不修改prevLine
) else (
set "prevLine="
)
)
if exist "%outputFile%" (
type "%outputFile%"
) else (
echo.
echo 【错误】无法提取系统版本信息!
pause >nul
goto select_image
)
:input_index
echo.
echo ==================================================
echo.
set /p image_index=. 请选择要安装的版本索引号:
if "%image_index%"=="" goto input_index
findstr /c:"索引: %image_index%" "%WORK_DIR%\image_info.txt" >nul
if errorlevel 1 (
echo 【错误】索引号 %image_index% 不存在!
goto input_index
)
set "GLOBAL_IMAGE_INDEX=%image_index%"
call :save_global_vars :: 保存索引号
echo.
echo [√] 已选择版本索引号:%image_index%
pause >nul
:confirm_install
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 重要警告 ║
echo ╚══════════════════════════════════════════════════╝
echo.
echo 【注意】目标分区 %GLOBAL_TARGET_DRIVE%: 上的所有数据将被永久删除!
echo.
set /p format_confirm=. 确认要格式化分区并安装系统吗?(输入YES继续):
if /i not "%format_confirm%"=="YES" (
echo.
echo 操作已取消。
call :remove_temp_drive
pause >nul
exit /b 1
)
:format_target
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 格式化目标分区 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ ║
echo ║ 正在格式化目标分区... ║
echo ║ ║
echo ╚══════════════════════════════════════════════════╝
echo.
echo select disk %GLOBAL_TARGET_DISK% > "%WORK_DIR%\format.txt"
echo select partition %GLOBAL_TARGET_PARTITION% >> "%WORK_DIR%\format.txt"
echo format fs=NTFS quick label="Windows" >> "%WORK_DIR%\format.txt"
echo assign letter=%GLOBAL_TARGET_DRIVE% >> "%WORK_DIR%\format.txt"
echo exit >> "%WORK_DIR%\format.txt"
diskpart /s "%WORK_DIR%\format.txt"
if errorlevel 1 (
echo.
echo 【错误】格式化失败!
pause >nul
exit /b 1
)
echo.
echo [√] 格式化完成
pause >nul
:apply_image
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 应用系统映像 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ 正在应用系统映像到目标分区... ║
echo ║ 这可能需要较长时间,请耐心等待... ║
echo ╚══════════════════════════════════════════════════╝
echo.
dism /Apply-Image /ImageFile:"%GLOBAL_SOURCE_PATH%" /Index:%GLOBAL_IMAGE_INDEX% /ApplyDir:%GLOBAL_TARGET_DRIVE%:\
if errorlevel 1 (
echo.
echo 【错误】应用映像失败!
pause >nul
call :error_cleanup
exit /b 1
)
:: 标记系统分区盘符(用于后续无人值守和引导修复)
set "GLOBAL_SYSTEM_DRIVE=%GLOBAL_TARGET_DRIVE%"
call :save_global_vars :: 关键:保存系统分区信息
echo.
echo [√] 系统映像应用成功!
pause >nul
call :repair_boot :: 部署完成后自动修复引导
exit /b 0
:: 修复引导记录(基于目标磁盘和系统分区)
:repair_boot
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 修复引导记录 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ ║
echo ║ 正在修复系统引导... ║
echo ║ ║
echo ╚══════════════════════════════════════════════════╝
echo.
:: 检查必要变量,若未定义则提示输入
if not defined GLOBAL_TARGET_DISK (
echo.
echo 【提示】未找到目标磁盘信息,请手动输入
set /p GLOBAL_TARGET_DISK=. 请输入目标磁盘编号(例如0):
if "!GLOBAL_TARGET_DISK!"=="" (
echo.
echo 【错误】磁盘编号不能为空!
pause >nul
exit /b 1
)
)
if not defined GLOBAL_SYSTEM_DRIVE (
echo.
echo 【提示】未能确定系统分区信息,请手动输入要植入的目标分区
echo.
set /p GLOBAL_SYSTEM_DRIVE=. 请输入系统分区盘符(例如 X):
if "!GLOBAL_SYSTEM_DRIVE!"=="" (
echo 【错误】盘符不能为空!
pause >nul
exit /b 1
)
set "GLOBAL_SYSTEM_DRIVE=!GLOBAL_SYSTEM_DRIVE::=!" :: 移除可能的冒号
)
set "target_disk=!GLOBAL_TARGET_DISK!"
set "system_drive=!GLOBAL_SYSTEM_DRIVE!"
set "esp_drive=S"
:: 在目标磁盘中查找ESP分区
echo select disk %target_disk% > "%WORK_DIR%\find_esp.txt"
echo list partition >> "%WORK_DIR%\find_esp.txt"
diskpart /s "%WORK_DIR%\find_esp.txt" | find "系统" > "%WORK_DIR%\esp_info.txt" 2>&1
diskpart /s "%WORK_DIR%\find_esp.txt" | find "EFI" >> "%WORK_DIR%\esp_info.txt" 2>&1
set esp_found=0
for /f "tokens=2" %%i in ('type "%WORK_DIR%\esp_info.txt" ^| find "分区"') do (
if !esp_found! equ 0 (
set esp_partition=%%i
set esp_found=1
)
)
if !esp_found! equ 1 (
echo select disk %target_disk% > "%WORK_DIR%\assign_esp.txt"
echo select partition !esp_partition! >> "%WORK_DIR%\assign_esp.txt"
echo assign letter=%esp_drive% >> "%WORK_DIR%\assign_esp.txt"
echo exit >> "%WORK_DIR%\assign_esp.txt"
diskpart /s "%WORK_DIR%\assign_esp.txt" >nul 2>&1
if exist "%esp_drive%:\" (
:: 强制使用系统分区修复引导(解决盘符混乱问题)
bcdboot %system_drive%:\Windows /s %esp_drive%: /f UEFI
if errorlevel 1 (
echo.
echo 【警告】UEFI引导创建失败,尝试BIOS引导...
bcdboot %system_drive%:\Windows /s %esp_drive%: /f BIOS
)
set "GLOBAL_ESP_DRIVE=%esp_drive%"
set "GLOBAL_ESP_PARTITION=!esp_partition!"
call :save_global_vars
echo.
echo [√] 引导修复成功(目标磁盘%target_disk%,系统分区%system_drive%:)
) else (
echo.
echo 【错误】ESP分区挂载失败,无法修复引导!
pause >nul
call :error_cleanup
exit /b 1
)
) else (
echo.
echo 【错误】在目标磁盘%target_disk%中未找到ESP分区!
echo.
echo 请确保目标磁盘已创建EFI系统分区(通常大小100-500MB)
pause >nul
call :error_cleanup
exit /b 1
)
echo.
echo [√] 引导修复完成!
call :cleanup
pause >nul
exit /b 0
:: 部署无人值守文件(确保生成到目标分区)
:deploy_unattend
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 部署无人值守安装文件 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ ║
echo ║ 请先选择目标系统分区 ║
echo ║ ║
echo ╚══════════════════════════════════════════════════╝
echo.
:: 检查系统分区变量,未定义则提示输入
if not defined GLOBAL_SYSTEM_DRIVE (
echo.
echo 【提示】未找到系统分区信息,请手动输入
set /p sys_drive=. 请输入系统分区盘符(例如X):
if "!sys_drive!"=="" (
echo.
echo 【错误】盘符不能为空!
pause >nul
exit /b 1
)
set "GLOBAL_SYSTEM_DRIVE=!sys_drive::=!" :: 移除冒号
call :save_global_vars :: 保存用户输入的盘符
)
:: 验证系统分区是否存在
set "system_drive=!GLOBAL_SYSTEM_DRIVE!"
if not exist "!system_drive!:\" (
echo.
echo 【错误】系统分区 !system_drive!: 不存在!
pause >nul
exit /b 1
)
:: 定义无人值守文件路径(关键:确保路径正确)
set "TARGET_DIR=!system_drive!:\Windows\Panther"
set "TARGET_FILE=!TARGET_DIR!\unattend.xml"
set "SOURCE_FILE=%WORK_DIR%\unattend.xml"
echo.
echo 正在创建无人值守文件...
(
echo ^
echo ^
echo ^
echo ^
echo ^[U]
echo ^
echo ^
echo ^
echo ^
echo ^true^
echo ^[/U]
echo ^
echo ^
echo ^
echo ^1^
echo ^reg add HKLM\SYSTEM\Setup\LabConfig /v BypassTPMCheck /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^2^
echo ^reg add HKLM\SYSTEM\Setup\LabConfig /v BypassSecureBootCheck /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^3^
echo ^reg add HKLM\SYSTEM\Setup\LabConfig /v BypassRAMCheck /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^
echo ^4^
echo ^reg add HKLM\System\Setup\LabConfig /v BypassStorageCheck /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^5^
echo ^reg add HKLM\System\Setup\LabConfig /v BypassCPUCheck /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^6^
echo ^reg add HKLM\SYSTEM\Setup\MoSetup /v AllowUpgradesWithUnsupportedTPMOrCPU /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^
echo ^
echo ^
echo ^
echo ^
echo ^
echo ^
echo ^1^
echo ^reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OOBE /v BypassNRO /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^
echo ^2^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Systray /v HideSystray /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^3^
echo ^reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^4^
echo ^reg add HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^5^
echo ^reg add HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server /v fDenyTSConnections /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^6^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Dsh /v AllowNewsAndInterests /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^7^
echo ^reg add HKLM\SYSTEM\CurrentControlSet\Control\BitLocker /v PreventDeviceEncryption /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^8^
echo ^reg add HKLM\Software\Policies\Microsoft\Edge /v HideFirstRunExperience /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^9^
echo ^reg add HKLM\Software\Policies\Microsoft\Edge\Recommended /v BackgroundModeEnabled /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^10^
echo ^reg add HKLM\Software\Policies\Microsoft\Edge\Recommended /v StartupBoostEnabled /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^11^
echo ^reg add HKU\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\GameDVR /v AppCaptureEnabled /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^12^
echo ^reg add HKU\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^13^
echo ^reg add HKU\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoAutorun /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^14^
echo ^reg add HKU\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDriveTypeAutoRun /t REG_DWORD /d 255 /f^
echo ^
echo ^
echo ^15^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender /v DisableAntiSpyware /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^16^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender /v DisableRoutinelyTakingAction /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^17^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection /v DisableRoutinelyTakingAction /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^18^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection /v DisableIOAVProtection /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^19^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection /v DisableOnAccessProtection /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^20^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection /v DisableRealtimeMonitoring /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^21^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection /v DisableAsyncScanOnOpen /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^22^
echo ^reg add HKLM\SOFTWARE\Microsoft\Security Center /v FirstRunDisabled /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^23^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications /v DisableNotifications /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^24^
echo ^reg add HKU\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel /v "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^25^
echo ^reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDriveTypeAutoRun /t REG_DWORD /d 255 /f^
echo ^
echo ^
echo ^26^
echo ^reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoAutorun /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^27^
echo ^reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer /v SmartScreenEnabled /t REG_SZ /d off /f^
echo ^
echo ^
echo ^28^
echo ^reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons /v 29 /t REG_SZ /d "%systemroot%\system32\imageres.dll,197" /f^
echo ^
echo ^
echo ^29^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\MRT /v DontOfferThroughWUAU /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^30^
echo ^reg add HKLM\SOFTWARE\Policies\Microsoft\Windows NT\SystemRestore /v DisableSR /t REG_DWORD /d 1 /f^
echo ^
echo ^
echo ^31^
echo ^reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^32^
echo ^reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0 /f^
echo ^
echo ^
echo ^
echo ^
echo ^
echo ^
echo ^
echo ^[U]
echo ^
echo ^^
echo ^true^
echo ^
echo ^[/U]
echo ^
echo ^[U]Administrator^[/U]
echo ^true^
echo ^1^
echo ^
echo ^^
echo ^true^
echo ^
echo ^
echo ^
echo ^3^
echo ^
echo ^true^
echo ^true^
echo ^true^
echo ^true^
echo ^Work^
echo ^true^
echo ^true^
echo ^
echo ^
echo ^
echo ^
echo ^1^
echo ^%windir%\Panther\Optimizer.cmd^
echo ^运行优化脚本^
echo ^
echo ^
echo ^中国标准时间^
echo ^
echo ^
echo ^[I]00000804^[/I]
echo ^zh-CN^
echo ^[U]zh-CN^[/U]
echo ^[U]zh-CN^[/U]
echo ^[U]en-US^[/U]
echo ^
echo ^
echo ^true^
echo ^
echo ^
echo ^1^
echo ^
echo ^
echo ^
) > "!SOURCE_FILE!"
:: 确保目标目录存在(关键:解决目录不存在导致的生成失败)
if not exist "!TARGET_DIR!" (
mkdir "!TARGET_DIR!" >nul 2>&1
if errorlevel 1 (
echo.
echo 【错误】无法创建目录 !TARGET_DIR!(权限不足或分区未挂载)
pause >nul
exit /b 1
)
)
:: 复制无人值守文件到目标位置
copy /y "!SOURCE_FILE!" "!TARGET_FILE!" >nul 2>&1
if errorlevel 1 (
echo.
echo 【错误】无法复制无人值守文件到 !TARGET_FILE!
echo 请检查系统分区是否可写(是否已格式化且挂载)
pause >nul
exit /b 1
)
:: 验证文件是否生成成功
if exist "!TARGET_FILE!" (
echo.
echo [√] 无人值守文件部署成功:!TARGET_FILE!
) else (
echo.
echo 【错误】无人值守文件生成失败!
pause >nul
exit /b 1
)
pause >nul
exit /b 0
:: 修复UEFI引导(独立功能,兼容单独调用)
:repair_uefi
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ UEFI引导修复工具 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ ║
echo ║ 下面开始修复 UEFI 引导 ║
echo ║ ║
echo ╚══════════════════════════════════════════════════╝
echo.
:: 检查并加载系统分区信息
if not defined GLOBAL_SYSTEM_DRIVE (
set /p system_drive=. 请输入系统分区盘符(例如X):
if "!system_drive!"=="" (
echo.
echo 【错误】盘符不能为空!
pause >nul
exit /b 1
)
set "GLOBAL_SYSTEM_DRIVE=!system_drive::=!"
call :save_global_vars
)
:: 检查并加载目标磁盘信息
if not defined GLOBAL_TARGET_DISK (
echo list disk > "%WORK_DIR%\listdisk.txt"
diskpart /s "%WORK_DIR%\listdisk.txt"
echo.
set /p uefi_disk=. 请输入目标硬盘编号(例如0):
if "!uefi_disk!"=="" (
echo.
echo 【错误】磁盘编号不能为空!
pause >nul
exit /b 1
)
set "GLOBAL_TARGET_DISK=!uefi_disk!"
call :save_global_vars
)
:: 调用修复引导核心逻辑
call :repair_boot
exit /b 0
:: 工具函数:保存全局变量到文件(解决变量继承问题)
:save_global_vars
(
echo set "GLOBAL_SOURCE_PATH=%GLOBAL_SOURCE_PATH%"
echo set "GLOBAL_TARGET_DRIVE=%GLOBAL_TARGET_DRIVE%"
echo set "GLOBAL_TARGET_DISK=%GLOBAL_TARGET_DISK%"
echo set "GLOBAL_TARGET_PARTITION=%GLOBAL_TARGET_PARTITION%"
echo set "GLOBAL_IMAGE_INDEX=%GLOBAL_IMAGE_INDEX%"
echo set "GLOBAL_SYSTEM_DRIVE=%GLOBAL_SYSTEM_DRIVE%"
echo set "GLOBAL_ESP_DRIVE=%GLOBAL_ESP_DRIVE%"
echo set "GLOBAL_ESP_PARTITION=%GLOBAL_ESP_PARTITION%"
) > "!GLOBAL_VARS!"
exit /b 0
:: 工具函数:加载全局变量(从文件读取)
:load_global_vars
if exist "!GLOBAL_VARS!" (
for /f "delims=" %%i in ('type "!GLOBAL_VARS!"') do (
%%i
)
)
exit /b 0
:: 工具函数:移除临时盘符
:remove_temp_drive
if defined GLOBAL_TARGET_DRIVE (
echo select disk %GLOBAL_TARGET_DISK% > "%WORK_DIR%\remove_temp.txt"
echo select partition %GLOBAL_TARGET_PARTITION% >> "%WORK_DIR%\remove_temp.txt"
echo remove letter=%GLOBAL_TARGET_DRIVE% >> "%WORK_DIR%\remove_temp.txt"
echo exit >> "%WORK_DIR%\remove_temp.txt"
diskpart /s "%WORK_DIR%\remove_temp.txt" >nul 2>&1
)
exit /b 0
:: 工具函数:清理临时文件和盘符
:cleanup
call :remove_temp_drive
if defined GLOBAL_ESP_DRIVE (
echo select disk %GLOBAL_TARGET_DISK% > "%WORK_DIR%\remove_esp.txt"
echo select partition %GLOBAL_ESP_PARTITION% >> "%WORK_DIR%\remove_esp.txt"
echo remove letter=%GLOBAL_ESP_DRIVE% >> "%WORK_DIR%\remove_esp.txt"
echo exit >> "%WORK_DIR%\remove_esp.txt"
diskpart /s "%WORK_DIR%\remove_esp.txt" >nul 2>&1
)
exit /b 0
:: 错误清理
:error_cleanup
call :cleanup
exit /b 1
:: 退出工具
:exit_tool
cls
echo.
echo ╔══════════════════════════════════════════════════╗
echo ║ 感谢使用 ║
echo ╠══════════════════════════════════════════════════╣
echo ║ ║
echo ║ 感谢使用Windows系统部署工具! ║
echo ║ 请重启并完成后续安装过程…… ║
echo ║ ║
echo ╚══════════════════════════════════════════════════╝
echo.
rd /s /q "%WORK_DIR%" >nul 2>&1
endlocal :: 最后退出时关闭局部环境
exit

