
承接https://cloud.tencent.com/developer/article/2475931,继续对https://schneegans.de/windows/unattend-generator/ 生成的win10/win11内核Windows系统(含Server2016~2025)自动应答文件做一下简单解析。涉及到的脚本内容远不止于下面这些,对细节感兴趣的可以再深入去查。
$scripts = @(
{
reg.exe add "HKLM\SYSTEM\Setup\MoSetup" /v AllowUpgradesWithUnsupportedTPMOrCPU /t REG_DWORD /d 1 /f;
};
{
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OOBE" /v BypassNRO /t REG_DWORD /d 1 /f;
};
{
net.exe accounts /maxpwage:UNLIMITED;
};
{
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 0 /f
};
{
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f
};
{
netsh.exe advfirewall firewall set rule group="@FirewallAPI.dll,-28752" new enable=Yes;
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f;
};
{
auditpol.exe /set /subcategory:"Process Creation" /success:enable /failure:enable;
};
{
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit" /v ProcessCreationIncludeCmdLine_Enabled /t REG_DWORD /d 1 /f;
};
{
Set-ExecutionPolicy -Scope 'LocalMachine' -ExecutionPolicy 'RemoteSigned' -Force;
};
{
fsutil.exe behavior set disableLastAccess 1;
};
{
reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v AUOptions /t REG_DWORD /d 4 /f;
reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoRebootWithLoggedOnUsers /t REG_DWORD /d 1 /f;
};
{
Register-ScheduledTask -TaskName 'MoveActiveHours' -Xml $( Get-Content -LiteralPath 'C:\Windows\Setup\Scripts\MoveActiveHours.xml' -Raw );
};
{
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /v HiberbootEnabled /t REG_DWORD /d 0 /f;
};
{
reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Dsh" /v AllowNewsAndInterests /t REG_DWORD /d 0 /f;
};
{
reg.exe add "HKLM\Software\Policies\Microsoft\Windows\CloudContent" /v "DisableWindowsConsumerFeatures" /t REG_DWORD /d 0 /f;
};
{
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\BitLocker" /v "PreventDeviceEncryption" /t REG_DWORD /d 1 /f;
};
{
reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Edge" /v HideFirstRunExperience /t REG_DWORD /d 1 /f;
};
{
C:\Windows\Setup\Scripts\unattend-01.cmd;
};
);这段 PowerShell 脚本定义了一个名为 $scripts 的数组,其中包含了一系列的脚本块(每个脚本块用大括号 {} 包围)。每个脚本块执行一组特定的 Windows 系统配置命令。以下是对每个脚本块功能的详细解释:
允许不受支持的 TPM 或 CPU 升级
reg.exe add "HKLM\SYSTEM\Setup\MoSetup" /v AllowUpgradesWithUnsupportedTPMOrCPU /t REG_DWORD /d 1 /f修改注册表以允许系统在 TPM 或 CPU 不受支持的情况下进行升级。
绕过网络引导选项 (NRO)
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OOBE" /v BypassNRO /t REG_DWORD /d 1 /f设置注册表项以跳过网络引导选项,加快首次启动过程。
设置密码永不过期
net.exe accounts /maxpwage:UNLIMITED将系统账户密码的最大年龄设置为无限,防止密码过期。
禁用用户账户控制 (UAC)
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 0 /f通过修改注册表禁用用户账户控制,减少权限提示。
启用长路径支持
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f启用文件系统的长路径支持,允许使用超过 260 个字符的文件路径。
配置防火墙和远程桌面
netsh.exe advfirewall firewall set rule group="@FirewallAPI.dll,-28752" new enable=Yes
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f启用特定防火墙规则并允许远程桌面连接。
启用进程创建审计
auditpol.exe /set /subcategory:"Process Creation" /success:enable /failure:enable启用对进程创建的成功和失败事件的审计。
记录命令行信息
reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit" /v ProcessCreationIncludeCmdLine_Enabled /t REG_DWORD /d 1 /f修改注册表以在审计日志中包含进程创建的命令行信息。
设置执行策略
Set-ExecutionPolicy -Scope 'LocalMachine' -ExecutionPolicy 'RemoteSigned' -Force设置本地计算机的 PowerShell 执行策略为 RemoteSigned,允许运行本地创建的脚本和从互联网下载的签名脚本。
禁用最后访问时间更新
fsutil.exe behavior set disableLastAccess 1禁用文件系统的最后访问时间更新,提高文件操作性能。
配置 Windows 更新设置
reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v AUOptions /t REG_DWORD /d 4 /f
reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoRebootWithLoggedOnUsers /t REG_DWORD /d 1 /f
设置 Windows 更新选项为自动下载并通知安装,同时禁止在有用户登录时自动重启。
注册计划任务
Register-ScheduledTask -TaskName 'MoveActiveHours' -Xml $( Get-Content -LiteralPath 'C:\Windows\Setup\Scripts\MoveActiveHours.xml' -Raw )注册一个名为 MoveActiveHours 的计划任务,具体行为由提供的 XML 文件定义。
禁用休眠功能
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /v HiberbootEnabled /t REG_DWORD /d 0 /f禁用系统的休眠功能。
禁用新闻和兴趣功能
reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Dsh" /v AllowNewsAndInterests /t REG_DWORD /d 0 /f禁用新闻和兴趣功能。
启用消费者功能
reg.exe add "HKLM\Software\Policies\Microsoft\Windows\CloudContent" /v "DisableWindowsConsumerFeatures" /t REG_DWORD /d 0 /f启用 Windows 的消费者功能,如应用商店等。
防止设备加密
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\BitLocker" /v "PreventDeviceEncryption" /t REG_DWORD /d 1 /f防止系统对设备进行自动加密。
隐藏 Edge 浏览器首次运行体验
reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Edge" /v HideFirstRunExperience /t REG_DWORD /d 1 /f隐藏 Microsoft Edge 浏览器的首次运行引导界面。
执行未提供的脚本
C:\Windows\Setup\Scripts\unattend-01.cmd执行位于 C:\Windows\Setup\Scripts\ 目录下的 unattend-01.cmd 脚本,具体功能取决于该脚本的内容。
这里顺便也分享下Windows安装盘ISO中setup.exe配合自动应答文件的几个常见参数
最重要是

/Auto
自动升级到更高版本的 Windows。
语法 /Auto {Clean | DataOnly | Upgrade}
不适用winpe
从 Windows 11 版本 22H2 开始,指定 Upgrade 选项要求安装媒体与目标设备具有相同的系统默认 UI 语言。 在早期版本的 Windows 中,可以执行一些跨语言部署(例如,en-US 到 en-GB),但不再允许这些类型的升级。
Clean:执行 Windows 的全新安装。
DataOnly:执行 Windows 升级,仅保存数据(而不保存应用)。
Upgrade:执行 Windows 升级,保存应用和数据。 /CompactOS
setup /compactos enable
指定是否使用精简 OS 功能来节省硬盘空间。
语法
/CompactOS {Enable | Disable}
适用winpe
/ImageIndex
指示 Windows 安装程序要从 install.wim 安装哪个操作系统映像(如果有多个适用的映像)
setup.exe /auto upgrade /quiet /compat ignorewarning /imageindex 2 /pkey xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
适用winpe
/PKey
为 Windows 安装程序提供特定的产品密钥。
语法
/PKey <product key>
setup.exe /auto upgrade /pkey xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
此选项是从 Windows 10 开始引入的新选项。 从 Windows 11 版本 24H2 开始,WinPE 提供支持。
适用winpe
/InstallDrivers
将 .inf 样式的驱动程序添加到新的 Windows 10 安装
setup.exe /auto upgrade /installdrivers x:\path\drivers /noreboot
此选项是从 Windows 10 开始引入的新选项。 驱动程序 .inf 可以位于指定位置的文件夹中。 该命令将在指定的位置循环递归。 从 Windows 11 版本 24H2 开始,WinPE 提供支持。
适用winpe
/InstallFrom
指定在 Windows 安装期间使用的另一个 Install.wim 文件。
setup /installfrom D:\custom.wim
这使你可以使用一个预安装环境来安装多个版本的 Windows 映像。 例如,可以使用 32 位版本的 Windows 安装程序来部署 64 位 Windows 映像。
适用winpe
/PostOOBE
Windows 安装程序完成后运行脚本。
语法
/PostOOBE<location> [\setupcomplete.cmd]
setup.exe /auto upgrade /postoobe C:\Fabrikam\setupcomplete.cmd
包含名为 setupcomplete.cmd 的脚本的文件夹的路径。setupcomplete.cmd 将复制到 $Windows.~BT,以便在 OOBE 之后运行。
此选项从 Windows 10 开始可用。 从 Windows 11 版本 24H2 开始,WinPE 提供支持。
适用winpe
比如在winpe下操作安装(具体化参数,比如下面命令里ISO挂载位置是G:,驱动位置是F:\amd64,应答文件位置是F:\notautounattend.xml)
G:\setup.exe /installfrom G:\sources\install.wim /installdrivers F:\amd64 /NoReboot /Unattend:F:\notautounattend.xml原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。