其他分享
首页 > 其他分享> > USMT具体步骤

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扩展点脚本

@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

@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

<?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
<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>

标签:RECOVERY,%%,Windows,USMT,CDIR%,具体步骤,HKLM,Microsoft
来源: https://blog.csdn.net/Bruce_4/article/details/120547983