USMT具体步骤
作者:互联网
准备 ScanState 工具
C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\User State Migration Tool\amd64
C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Setup\amd64\Sources
准备PBR扩展点脚本
- 创建脚本 (.cmd) 或可执行文件 (.exe) 以在“保留我的文件”功能运行时在可用的扩展点运行:
- BasicReset_BeforeImageApply
- BasicReset_AfterImageApply
@ECHO OFF
:START
SET RECOVERY=
SET CDIR=
SET CURRDRV=%~d0
SET VOL=Windows
REM Define RECOVERY
REM USB Based Recovery
if exist %CURRDRV%\SOURCES\Reconstruct.WIM set RECOVERY=%CURRDRV%\SOURCES\OEM
REM C Based Recovery
IF NOT DEFINED RECOVERY FOR /F "usebackq tokens=1-6 delims== " %%A IN (`echo list vol ^|diskpart`) DO IF /I %%D==%vol% SET RECOVERY=%%C:\Recovery\OEM
REM TARGEOS and TARGETOSDRIVE from REGISTRY
IF NOT DEFINED RECOVERY FOR /F "tokens=1,2,3 delims= " %%A IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RecoveryEnvironment" /v TargetOS') DO SET TARGETOS=%%C
IF NOT DEFINED RECOVERY SET RECOVERY=%TARGETOS:~0,2%\RECOVERY\OEM
REM Define CDIR
FOR /F "usebackq tokens=1-6 delims== " %%A IN (`echo list vol ^|diskpart`) DO IF /I %%D==%vol% SET CDIR=%%C
IF NOT DEFINED CDIR FOR /F "tokens=1,2,3 delims= " %%A IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RecoveryEnvironment" /v TargetOS') DO SET TARGETOS=%%C
IF NOT DEFINED CDIR SET CDIR=%TARGETOS:~0,1%
IF NOT DEFINED RECOVERY GOTO END
GOTO RUNCMD
:RUNCMD
ECHO TargetOS is: %CDIR% >> %RECOVERY%\RECOVERY.LOG
ECHO Recovery location is: %RECOVERY% >> %RECOVERY%\RECOVERY.LOG
ECHO %DATE% %TIME% Reset Extensibility Commands >> %RECOVERY%\RECOVERY.LOG
if exist %CDIR%:\Windows\Preload.log (
attrib +h %CDIR%:\Windows\Preload.log
)
if exist %CDIR%:\PerfLogs (
attrib +h %CDIR%:\PerfLogs
)
if exist %CDIR%:\Windows.old (
attrib +h %CDIR%:\Windows.old
)
echo.%PROCESSOR_IDENTIFIER% | find /i "Intel" || set PLATFORMAMD=TRUE
if not defined PLATFORMAMD (
if not exist %CDIR%:\Intel MD %CDIR%:\Intel
attrib +h %CDIR%:\Intel
)
XCOPY %RECOVERY%\C\*.* %CDIR%:\*.* /cherky
if errorlevel 1 ECHO %1 Returned %errorlevel% >> %RECOVERY%\RECOVERY.LOG
if exist C:\Windows\OEMSetting.CMD (
call C:\Windows\OEMSetting.CMD
)
exit /b
:END
- 创建脚本 (.cmd) 或可执行文件 (.exe) 以在“删除所有内容”功能运行时在可用的扩展点运行:
- FactoryReset_AfterDiskFormat
- FactoryReset_AfterImageApply
@ECHO OFF
:START
SET RECOVERY=
SET CDIR=
SET CURRDRV=%~d0
SET VOL=Windows
REM Define RECOVERY
REM USB Based Recovery
if exist %CURRDRV%\SOURCES\Reconstruct.WIM set RECOVERY=%CURRDRV%\SOURCES\OEM
REM C Based Recovery
IF NOT DEFINED RECOVERY FOR /F "usebackq tokens=1-6 delims== " %%A IN (`echo list vol ^|diskpart`) DO IF /I %%D==%vol% SET RECOVERY=%%C:\Recovery\OEM
REM TARGEOS and TARGETOSDRIVE from REGISTRY
IF NOT DEFINED RECOVERY FOR /F "tokens=1,2,3 delims= " %%A IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RecoveryEnvironment" /v TargetOS') DO SET TARGETOS=%%C
IF NOT DEFINED RECOVERY SET RECOVERY=%TARGETOS:~0,2%\RECOVERY\OEM
REM Define CDIR
FOR /F "usebackq tokens=1-6 delims== " %%A IN (`echo list vol ^|diskpart`) DO IF /I %%D==%vol% SET CDIR=%%C
IF NOT DEFINED CDIR FOR /F "tokens=1,2,3 delims= " %%A IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RecoveryEnvironment" /v TargetOS') DO SET TARGETOS=%%C
IF NOT DEFINED CDIR SET CDIR=%TARGETOS:~0,1%
IF NOT DEFINED RECOVERY GOTO END
GOTO RUNCMD
:RUNCMD
ECHO TargetOS is: %CDIR% >> %RECOVERY%\RECOVERY.LOG
ECHO Recovery location is: %RECOVERY% >> %RECOVERY%\RECOVERY.LOG
ECHO %DATE% %TIME% Reset Extensibility Commands >> %RECOVERY%\RECOVERY.LOG
if exist %CDIR%:\Windows\Preload.log (
attrib +h %CDIR%:\Windows\Preload.log
)
if exist %CDIR%:\PerfLogs (
attrib +h %CDIR%:\PerfLogs
)
if exist %CDIR%:\Windows.old (
attrib +h %CDIR%:\Windows.old
)
echo.%PROCESSOR_IDENTIFIER% | find /i "Intel" || set PLATFORMAMD=TRUE
if not defined PLATFORMAMD (
if not exist %CDIR%:\Intel MD %CDIR%:\Intel
attrib +h %CDIR%:\Intel
)
XCOPY %RECOVERY%\C\*.* %CDIR%:\*.* /cherky
if errorlevel 1 ECHO %1 Returned %errorlevel% >> %RECOVERY%\RECOVERY.LOG
exit /b
:END
- 创建一个 ResetConfig.xml 文件,该文件指定您为四个扩展点创建的脚本的位置
- 如果使用文本编辑器创作 ResetConfig.xml 文件,请使用 .xml 文件扩展名保存文档并使用 UTF-8 编码。不要使用 Unicode 或 ANSI
<?xml version="1.0" encoding="utf-8"?>
<Reset>
<Run Phase="BasicReset_AfterImageApply">
<Path>scripts\RefreshPost.cmd</Path>
<Param></Param>
<Duration>2</Duration>
</Run>
<Run Phase="FactoryReset_AfterImageApply">
<Path>scripts\ResetPost.cmd</Path>
<Param></Param>
<Duration>2</Duration>
</Run>
<SystemDisk>
<MinSize>20000</MinSize>
<DiskpartScriptPath>pbr.txt</DiskpartScriptPath>
<OSPartition>3</OSPartition>
<WindowsREPartition>4</WindowsREPartition>
<WindowsREPath>Recovery\WindowsRE</WindowsREPath>
<Compact>False</Compact>
</SystemDisk>
</Reset>
- 创建用于初始部署的磁盘分区脚本
rem These commands are used with DiskPart tool.
rem Erase the drive and create four partitions
rem for a UEFI/GPT-based computer.
convert GPT
REM == Partition ESP1 ==
create partition efi size=100
format quick fs=fat32 label="SYSTEM"
assign letter="S" noerr
set id="c12a7328-f81f-11d2-ba4b-00a0c93ec93b"
gpt attributes=0x8000000000000001
REM == Partition MSR1 ==
create partition msr size=16
REM == Partition OS1 ==
create partition primary
shrink desired=1024
format quick fs=ntfs label="Windows"
assign letter="W" noerr
REM == Partition REC1 ==
create partition primary size=1024
format quick fs=ntfs label="WINRE"
assign letter="T" noerr
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
gpt attributes=0x8000000000000001
exit
scanstate\ScanState.exe /apps /config:pbr_config.xml /ppkg C:\Recovery\Customizations\USMT.PPKG /i:exclusion.xml /o /c /v:13 /l:%USMTLOGDIR%\ScanState.log
- pbr_config.xml为微软提供的配置文件
- exclusion.xml文件定义了scanstat要不要抓进usmt.ppkg的内容
- 以下为不包含的内容
<unconditionalExclude>
<objectSet>
<pattern type="Registry">HKLM\SYSTEM\CurrentControlSet\Control\CI\Policy [ManufacturingMode]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\Run [modify]</pattern>
<pattern type="File">%SystemDrive%\SWWORK\* [*]</pattern>
<pattern type="File">%SystemDrive%\AMD\* [*]</pattern>
<pattern type="File">%SystemDrive%\Intel\* [*]</pattern>
<pattern type="File">%SystemDrive%\Recovery\* [*]</pattern>
<pattern type="File">%SystemDrive%\ProgramData\Comms\PCManager\log\* [*]</pattern>
<pattern type="File">%SystemDrive%\ProgramData\Huawei\HmsCore\log\* [*]</pattern>
<pattern type="File">%SystemDrive%\Windows\System32 [qemuator_ipc_client.log]</pattern>
</objectSet>
</unconditionalExclude>
- 以下为包含的内容
<include>
<objectSet>
<pattern type="Registry">HKLM\Software\WowAA32Node\Microsoft\Windows\CurrentVersion\Internet Settings\Configuration [PartnerSearchCode]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Configuration [PartnerSearchCode]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\Themes [DesktopBackground]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\Themes [ThemeName]</pattern>
<!-- Maintain Office reg keys after PBR -->
<pattern type="Registry">HKLM\Software\Microsoft\Office\16.0\Common\OEM [OOBE]</pattern>
<pattern type="Registry">HKLM\Software\Wow6432Node\Microsoft\Office\16.0\Common\OEM [OOBE]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Office\16.0\Common\OEM [OOBEMode]</pattern>
<pattern type="Registry">HKLM\Software\Wow6432Node\Microsoft\Office\16.0\Common\OEM [OOBEMode]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\OfficeSoftwareProtectionPlatform [ReferralData]</pattern>
<pattern type="Registry">HKLM\Software\Wow6432Node\Microsoft\OfficeSoftwareProtectionPlatform [ReferralData]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion [C20CDB00F]</pattern>
<pattern type="Registry">HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion [C20CDB00F]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\C20CDB00F </pattern>
<pattern type="Registry">HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\C20CDB00F </pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\Store [OEMID]</pattern>
<pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer [LayoutXMLPath]</pattern>
<!-- <pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\Control Panel\Settings\Network [WiFiToWlan]</pattern> -->
<!-- <pattern type="Registry">HKLM\Software\Microsoft\Windows\CurrentVersion\DeviceAccess [ActivePolicyCode]</pattern> -->
<!-- Maintain DeviceForm reg keys after PBR -->
<pattern type="Registry">HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\OEM [DeviceForm]</pattern>
</objectSet>
</include>
- 生成的usmt.ppkg文件放到
C:\Recovery\Customizations\USMT.PPKG
目录,pbr会自动安装该目录下的配置包
标签:RECOVERY,%%,Windows,USMT,CDIR%,具体步骤,HKLM,Microsoft 来源: https://blog.csdn.net/Bruce_4/article/details/120547983