|
部署前 (Pre-deployment)
实现方式:
在封装时直接集成到系统镜像中
通过修改系统服务或启动项实现
利用Windows PE环境执行
具体实现方法:
服务方式
<BATCH>
# 创建自定义服务,设置为自动启动
sc create PreDeployService binPath="C:\PreDeploy\script.exe" start=auto
注册表启动项
<BATCH>
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "PreDeploy" /d "C:\PreDeploy\script.exe"
任务计划程序
<BATCH>
schtasks /create /tn "PreDeploy" /tr "C:\PreDeploy\script.exe" /sc onstart /ru system
部署后 (Post-deployment)
实现方式:
通过注册表Run/RunOnce键值
系统服务延迟启动
组策略脚本
具体实现方法:
RunOnce注册表项
<BATCH>
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v "PostDeploy" /d "C:\PostDeploy\cleanup.exe"
延迟启动服务
<BATCH>
sc create PostDeployService binPath="C:\PostDeploy\script.exe" start=delayed-auto
计划任务延迟执行
<BATCH>
schtasks /create /tn "PostDeploy" /tr "C:\PostDeploy\script.exe" /sc onstart /delay 0005:00
5个环节的执行顺序总结:
<TEXT>
部署前 → 部署中 → 部署后 → 登录时 → 进桌面
↓ ↓ ↓ ↓ ↓
服务/启动项 Unattend RunOnce FirstLogon LogonCommands
关键区别:
部署前/后:系统级执行,无用户界面
登录时/进桌面:用户级执行,可有界面交互 |
|