部署按鈕重設功能

按鈕重設功能隨附於 Windows 10 和 Windows 11 傳統型版本(家用版、專業版、企業版和教育版),不過您必須執行其他步驟,以使用下列自定義專案部署計算機:

  • Windows 傳統型應用程式
  • Windows 設定,例如自定義的 OOBE 畫面或 [開始功能表]。
  • 自訂的數據分割配置。

這些步驟也會示範如何在重設期間新增自己的腳本,以擷取記錄或執行其他清除工作。

必要條件

若要完成下列步驟,您需要具備 Windows 評定與部署套件 (ADK) 和 WinPE 附加元件的技術員電腦。 當您安裝 ADK 時,請選擇下列選項:

  • 部署工具
  • 映像處理和設定設計工具 (ICD)
  • 使用者狀態移轉工具 (USMT)

您也需要:

  • 磁碟驅動器大小為 100 GB 或更大的目的地電腦
  • 適用於桌面版本的 Windows 10 或 Windows 11 映射 (install.wim)
  • Windows RE 開機映射 (Winre.wim) (您將從 Windows 安裝映射中擷取此映射)。

如需整個部署程式的概觀,請參閱 桌面製造指南

使用下列步驟來準備 ScanState 工具,以在安裝 Windows 傳統型應用程式之後擷取這些應用程式:

步驟 1:準備 ScanState 工具

  1. 在技術人員計算機上,將 Windows ADK 檔案從 Windows 用戶狀態移轉工具 (USMT) 和 Windows 安裝程式複製到工作資料夾。 您必須符合目的地裝置的架構。 您不需要複製子資料夾。

    md C:\ScanState_amd64
    xcopy /E "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\User State Migration Tool\amd64" C:\ScanState_amd64
    xcopy /E /Y "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Setup\amd64\Sources" C:\ScanState_amd64
    
  2. 將工作資料夾的內容複製到網路位置或USB快閃磁碟驅動器。

如果需要其他驅動程式和語言套件,請使用下列步驟來自定義 Windows RE 開機映射。

步驟 2:擷取和自定義 Windows RE 開機映射 (選用)

  1. 在技術人員計算機上,按兩下 [開始],然後輸入部署。 以滑鼠右鍵按兩下 [部署和映像處理工具環境 ],然後選取 [ 以系統管理員身分執行]。

  2. [部署和映射處理工具環境] 中,建立資料夾結構來儲存 Windows 映射及其載入點。

    Mkdir C:\OS_image\mount
    
  3. 建立資料夾結構來儲存 Windows RE 開機映像及其載入點。

    Mkdir C:\winre_amd64\mount
    
  4. 使用 DISM 將 Windows 映射 (install.wim) 掛接至資料夾 \OS_image\mount。

    Dism /mount-image /imagefile:C:\OS_image\install.wim /index:1 /mountdir:C:\OS_image\mount
    

    其中 Index:1 是 Install.wim 檔案中所選映像的索引。

  5. 將 Windows RE 映射從掛接的 Windows 映射複製到新的資料夾。

    xcopy /H C:\OS_image\mount\windows\system32\recovery\winre.wim C:\winre_amd64 
    
  6. 取消掛接 Windows 映像。 提示:如果您尚未在 Windows 映射中進行任何其他變更,您可以使用 選項更快速地 /discard 取消掛接映射。

    Dism /unmount-image /mountdir:C:\OS_image\mount /discard
    
  7. 掛接 Windows RE 開機映射以進行編輯。

    Dism /mount-image /imagefile:C:\winre_amd64\winre.wim /index:1 /mountdir:C:\winre_amd64\mount
    

    其中 Index:1 是 Winre.wim 檔案中所選影像的數目。

    從 Install.wim 檔案擷取 Winre.wim 檔案之後,您可以自定義 Windows RE 開機映射。

  8. 將語言套件、開機關鍵設備驅動器和輸入設備驅動器新增至 Windows RE 開機映射。 若要深入瞭解,請參閱 自定義 Windows RE

  9. 認可您的自定義專案並取消掛接映像。

    Dism /unmount-image /mountdir:C:\winre_amd64\mount /commit 
    

如果您打算只自定義所有 Windows 10 版本通用的設定(包括 Windows 10 行動裝置版),請使用下列步驟來建立布建套件,以指定要在復原期間還原的設定:

步驟 3:(選擇性) 建立布建套件並設定要還原

  1. 在技術人員計算機上,啟動 Windows 映像處理和設定設計工具 (ICD)。
  2. 按兩下 [檔案>新專案]。
  3. 輸入項目名稱和描述,然後按 [ 下一步]
  4. 在 [ 選取專案工作流程 ] 步驟中,選取 [ 布建套件] 選項,然後按 [ 下一步]。
  5. 在 [ 選擇要檢視和設定 的設定] 步驟中,選取 [所有 Windows 版本的 通用] 選項,然後按 [ 下一步]。
  6. 在匯 入布建套件 (選擇性) 步驟中,按兩下 [ 完成 ] 以建立新的專案。
  7. 使用 [ 可用的自定義] 窗格來新增設定,並指定復原期間應還原的預設值。 這些設定會出現在 [ 選取的自定義] 窗格中。
  8. 按兩下 [匯出>布建套件]。
  9. 在 [ 描述布建套件 ] 步驟中,按 [ 下一步]。
  10. 在 [ 選取布建套件 步驟的安全性詳細數據] 中,按 [ 下一步]。
  11. 在 [ 選取要儲存布建套件 的位置] 步驟中,輸入儲存套件的位置(例如網络共用),然後按 [下一步]。
  12. 按兩下 [建置 ] 以建立布建套件。
  13. 建立布建套件之後,按兩下 [ 完成]。

如果您的自定義專案包含 Windows 10 傳統型版本特定的設定,請使用下列步驟來建立 unattend.xml,以指定要在復原期間還原的設定:

步驟 4:(選擇性) 建立自動檔案以還原設定

  1. 在技術人員計算機上,啟動 Windows 系統映像管理員
  2. 按兩下 [檔案>選取 Windows 映像]。
  3. 當系統提示您建立目錄檔案時,按兩下 [ ]。
  4. 使用 [Windows 映射和回應檔案] 窗格,將設定新增至[特製化] 或 [oobeSystem] 階段(或兩者),並指定復原期間應該還原的預設值。
  5. 按兩下 [工具>驗證回應檔案] 以檢查是否有錯誤。 更正任何已識別的問題。
  6. 按兩下 [檔案>儲存回應檔案]。 輸入位置以儲存回應檔案(例如網路共用),然後按兩下 [ 儲存]。

如果您打算使用按鈕重設的擴充點,請使用下列步驟來準備擴充點,並使用一個按鈕重設組態檔加以註冊。

重要

如果您已建立自動安裝檔案,您也必須建立腳本,以使用 和FactoryReset_AfterImageApply擴充點重新套用BasicReset_AfterImageApply它。

步驟 5:(選擇性) 準備按鈕重設擴充點腳本

  1. 建立腳本 (.cmd) 或可執行檔 (.exe) 以在 [保留我的檔案] 功能執行時,於可用的擴充點執行:

    • 答:BasicReset_BeforeImageApply
    • B:BasicReset_AfterImageApply
  2. 在 [移除所有專案] 功能執行時,建立腳本 (.cmd) 或可執行檔 (.exe) 以在可用的擴充點執行:

    • C:FactoryReset_AfterDiskFormat
    • D: FactoryReset_AfterImageApply
  3. 將腳本儲存到網路位置或 USB 快閃磁碟驅動器。

  4. 建立 ResetConfig.xml 檔案,指定您為四個擴充點建立的腳本位置。 例如:

    <?xml version="1.0" encoding="utf-8"?>
    <Reset>
        <Run Phase="BasicReset_BeforeImageApply">
            <Path>Fabrikam\SampleScript_A.cmd</Path>
            <Duration>2</Duration>
        </Run>
        <Run Phase="BasicReset_AfterImageApply">
            <Path>Fabrikam\SampleScript_B.cmd</Path>
            <Param></Param>
            <Duration>2</Duration>
        </Run>
        <Run Phase="FactoryReset_AfterDiskFormat">
            <Path>Fabrikam\SampleScript_C.cmd</Path>
            <Duration>2</Duration>
        </Run>
        <Run Phase="FactoryReset_AfterImageApply">
            <Path>Fabrikam\SampleScript_D.cmd</Path>
            <Param></Param>
            <Duration>2</Duration>
        </Run>
    </Reset>
    

    重要

    如果您使用文本編輯器來撰寫 ResetConfig.xml 檔案,請使用 .xml 擴展名儲存檔,並使用 UTF-8 編碼。 請勿使用 Unicode 或 ANSI。

  5. 將 ResetConfig.xml 檔案與您建立的腳本一起儲存。

步驟 6:(選擇性) 建立裸機復原設定

  • 若要指定當使用者使用從計算機建立的復原媒體執行裸機復原時要使用的分割區配置,請修改 resetconfig.xml 以包含下列元素:

    <?xml version="1.0" encoding="utf-8"?>
    <Reset>
            <SystemDisk>
            <MinSize>160000</MinSize>
            <DiskpartScriptPath>ReCreatePartitions.txt</DiskpartScriptPath>
            <OSPartition>3</OSPartition>
            <WindowsREPartition>4</WindowsREPartition>
            <WindowsREPath>Recovery\WindowsRE</WindowsREPath>
            <Compact>False</Compact>
    </SystemDisk>
    </Reset>
    
    • <MinSize> - 以 MB 為單位指定系統磁碟的大小下限。 如果系統磁碟不符合此最小大小,復原程式將不會繼續。
    • <DiskpartScriptPath> - 相對於 install.wim 位置的 Diskpart 腳本路徑。 腳本應該假設所有現有的分割區都已刪除,而系統磁碟在 Diskpart 中具有焦點。
    • <OSPartition> - 必須指定復原映射套用至其中的分割區。 ESP 或作用中磁碟分區必須與OS位於相同的磁碟上。
    • <WindowsREPartition>; <WindowsREPath> - (選擇性) 應暫存 WinRE 的位置。 媒體上的 WinRE 開機映射將會複製並向 OS 註冊。 (與執行 reagentc.exe /setreimage相同)

    如果未在 resetconfig.xml 中指定數據分割資訊,使用者仍然可以使用所建立的媒體執行裸機復原。 不過,將會改用 Windows 10 的預設/建議數據分割配置。

步驟 7:建立初始部署的 diskpart 腳本

  1. 建立初始部署的磁碟分割腳本。

    UEFI 範例

    rem These commands are used with DiskPart tool.
    rem Erase the drive and create four partitions
    rem for a UEFI/GPT-based PC.
    select disk 0
    clean
    convert gpt
    rem == 1. System Partition =======================
    create partition efi size=100
    rem ***NOTE: For 4KB-per-sector drives, change 
    rem this value to size=260.***
    format quick fs=fat32 label="System"
    assign letter="S"
    rem == 2. Microsoft Reserved (MSR) Partition =====
    create partition msr size=16
    rem == 3. Windows Partition ======================
    rem ==    a. Create Windows Partition ============
    create partition primary
    rem ==    b. Create space for Windows RE tools partition
    shrink minimum=450
    rem ==    c. Prepare the Windows partition
    format quick fs=ntfs label="Windows"
    assign letter="W"
    rem == 4. Windows RE Tools Partition =============
    create partition primary
    format quick fs=ntfs label="Windows RE tools"
    set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac
    assign letter="T"
    exit
    

    BIOS 範例

    rem These commands are used with DiskPart to 
    rem erase the drive and create three partitions 
    rem for a BIOS/MBR-based PC. 
    rem Adjust the partition sizes to fill the drive.
    select disk 0
    clean
    rem === 1. System Partition =====================
    create partition primary size=100
    format quick fs=ntfs label="System"
    assign letter="S" 
    active 
    rem === 2. Windows Partition ====================
    rem ==    a. Create Windows partition ===========
    create partition primary 
    rem ==    b. Create space for Windows RE tools partition ====
    shrink minimum=450
    rem ==    c. Prepare the Windows partition ======
    format quick fs=ntfs label="Windows" 
    assign letter="W" 
    rem === 3. Windows RE Tools Partition =============
    create partition primary
    format quick fs=ntfs label="Windows RE tools"
    set id=27
    assign letter="R" 
    exit
    
  2. 將腳本命名為 CreatePartitions-UEFI 或 CreatePartitions-BIOS.txt,並將它儲存到網路位置或 USB 快閃磁碟驅動器。 注意:在這些 Diskpart 範例中,分割區會指派字母 S:\、W:\和 T:\ 來簡化分割區識別。 計算機重新啟動之後,Windows PE 會自動將字母 C:\ 指派給 Windows 磁碟分區。 其他分割區不會收到驅動器號。

步驟 8:建立裸機復原的 diskpart 腳本 (選用)

  1. 建立裸機復原的 diskpart 腳本。

    重要

    用於裸機復原的 diskpart 腳本不應包含 select diskclean 命令。 系統會在處理 diskpart 腳本之前自動選取系統磁碟。 為了避免因磁碟分割大小而導致的裸機復原開機問題,建議製造商允許裸機復原功能自動產生的指令碼以建立用於復原 WIM 的磁碟分割。 如果製造商想要使用自訂的 DISKPART 指令碼來建立資料分割,建議的磁碟分割大小下限為 990 MB,可用空間下限則為 250MB。

    UEFI 範例

    rem These commands are used with DiskPart tool.
    rem Erase the drive and create five partitions
    rem for a UEFI/GPT-based PC.
    convert gpt
    rem == 1. System Partition =======================
    create partition efi size=100
    rem ***NOTE: For 4KB-per-sector drives, change 
    rem this value to size=260.***
    format quick fs=fat32 label="System"
    assign letter="S"
    rem == 2. Microsoft Reserved (MSR) Partition =====
    create partition msr size=16
    rem == 3. Windows Partition ======================
    rem ==    a. Create Windows Partition ============
    create partition primary
    rem ==    b. Create space for Windows RE tools partition
    shrink minimum=450
    rem ==    c. Prepare the Windows partition
    format quick fs=ntfs label="Windows"
    assign letter="W"
    rem == 4. Windows RE Tools Partition =============
    create partition primary
    format quick fs=ntfs label="Windows RE tools"
    set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac
    assign letter="T"
    exit
    

    BIOS 範例

    rem These commands are used with DiskPart to 
    rem erase the drive and create three partitions 
    rem for a BIOS/MBR-based PC. 
    rem Adjust the partition sizes to fill the drive.
    rem === 1. System Partition =====================
    create partition primary size=100
    format quick fs=ntfs label="System"
    assign letter="S" 
    active 
    rem === 2. Windows Partition ====================
    rem ==    a. Create Windows partition ===========
    create partition primary 
    rem ==    b. Create space for Windows RE tools partition ====
    shrink minimum=450
    rem ==    c. Prepare the Windows partition ======
    format quick fs=ntfs label="Windows" 
    assign letter="W" 
    rem === 3. Windows RE Tools Partition =============
    create partition primary
    format quick fs=ntfs label="Windows RE tools"
    set id=27
    assign letter="R" 
    exit
    
  2. 將腳本命名為 RecreatePartitions-UEFI.txt 或 RecreatePartitions-BIOS.txt,並將它儲存到相同的網路位置,或 USB 快閃磁碟驅動器作為建立磁碟分區。

步驟 9:部署和自定義 Windows

  1. 在目的地計算機上,開機至 Windows PE。

  2. 在 Windows PE 命令提示字元中,執行腳本以建立建議的硬碟磁碟分區。

    Diskpart /s N:\CreatePartitions.txt
    

    其中 N:\CreatePartition 是檔案的位置。

  3. 將 Windows 參考映射套用至 Windows 磁碟分區。

    Dism /Apply-Image /ImageFile:N:\Install.wim /Index:1 /ApplyDir:W:\
    

    選擇性:您也可以指定 /compact 選項,以便將寫入磁碟的檔案壓縮。 例如:

    Dism /Apply-Image /ImageFile:N:\Install.wim /Index:1 /ApplyDir:W:\ /Compact:on
    

    如果您要將 Windows 部署到具有有限儲存容量的電腦,但不建議在具有輪替儲存裝置的電腦上使用。

  4. 使用 BCDboot 設定系統分割區。

    W:\Windows\System32\Bcdboot W:\Windows
    
  5. 在 Windows RE 工具磁碟分區中建立資料夾,並將自定義 Windows RE 開機映射複製到該磁碟分區。

    Mkdir T:\Recovery\WindowsRE
    xcopy /H N:\Winre.wim T:\Recovery\WindowsRE
    

    其中 T:\ 是 Windows RE 工具磁碟分區。

    重要

    您必須將 Winre.wim 儲存在 \Recovery\WindowsRE 中。

  6. 將 Windows RE 開機映像與 Windows 映射一起註冊。

    W:\Windows\System32\Reagentc /setreimage /path T:\Recovery\WindowsRE /target W:\Windows
    
  7. 使用 Diskpart 從 Windows 檔案總管隱藏 Windows RE 工具 (T:\) 磁碟分區。

    針對以 UEFI 為基礎的電腦:

    select disk 0
    select partition 4
    remove
    set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac
    gpt attributes=0x8000000000000001
    exit
    

    針對 BIOS 型電腦:

    select disk 0
    select partition 3
    remove
    set id=27
    exit
    
  8. 自訂目的地電腦上的 Windows 映射:

    1. 對 Windows 映像執行離線自定義,例如安裝目的地電腦專屬的 INF 型驅動程式套件、安裝作業系統更新和語言套件,或布建其他 Windows 應用程式。
    2. 將目的地電腦開機至稽核模式。 這可以透過搭配 Microsoft-Windows-Deployment 使用響應檔案來完成 |重新密封 |模式 = 稽核設定,或先將計算機開機到 OOBE,然後按 CTRL+SHIFT+F3。
    3. 執行任何剩餘的自定義,例如安裝目的地計算機專屬的應用程式和裝置軟體套件。
  9. 清除映射:

    DISM.exe /Cleanup-Image /StartComponentCleanup
    

步驟 10:擷取和部署復原的自定義專案

  1. 建立 C:\Recovery 資料夾。 使用下列命令,以確保此資料夾已正確設定正確的許可權和 ACL。

    mkdir C:\Recovery
    icacls C:\Recovery /inheritance:r
    icacls C:\Recovery /grant:r SYSTEM:(OI)(CI)(F)
    icacls C:\Recovery /grant:r *S-1-5-32-544:(OI)(CI)(F)
    takeown /f C:\Recovery /a
    attrib +H C:\Recovery
    
  2. 使用 ScanState 工具,將已安裝的自定義專案擷取到布建套件中。 使用 /config 選項來指定 ADK 隨附的預設組態檔之一,並將 .ppkg 檔案儲存在 C:\Recovery\Customizations 資料夾中。

    N:\ScanState_amd64\scanstate.exe /apps /config:<path_to_config_file> /ppkg C:\Recovery\Customizations\apps.ppkg /o /c /v:13 /l:C:\ScanState.log
    

    其中 N:\ 是步驟 1 中安裝 ScanState 工具的位置。

  3. 如果您已使用 Windows ICD 建立其他佈建套件,其中包含應該在復原期間還原的自定義,請將套件複製到目的地電腦。 例如:

    xcopy N:\RecoveryPPKG\*.ppkg C:\Recovery\Customizations
    

    其中 N:\ 是其他布建套件所在的位置。

  4. 將任何一鍵重設組態檔 (resetconfig.xml) 和擴充性腳本複製到目的地計算機,然後設定寫入/修改許可權。 例如:

    mkdir C:\Recovery\OEM
    xcopy /E N:\RecoveryScripts\* C:\Recovery\OEM
    

    其中 N:\ 是組態檔和腳本所在的位置。

  5. 使用 Sysprep 工具來重新密封 Windows 映射,而不使用 /generalize 選項。

    Sysprep /oobe /exit
    

    重要

    您必須設定要寄送給客戶的映像,以開機至 OOBE。

  6. (選擇性)若要節省空間,您也可以將已安裝的 Windows 傳統型應用程式轉換成參考自定義套件的檔案指標。 若要這樣做,請將目的地電腦開機至 Windows PE 並執行下列動作:

    DISM /Apply-CustomDataImage /CustomDataImage:C:\Recovery\Customizations\USMT.ppkg /ImagePath:C:\ /SingleInstance
    
  7. 關閉目的地計算機以進行封裝和出貨。 當使用者第一次啟動計算機時,它會開機至 OOBE。

步驟 11:確認您的自定義專案

確認您的自定義項目在復原后已還原,並執行 [保留我的檔案] 和 [移除所有專案] 功能,以繼續運作。 若要開始,請檢查下列進入點:

  • 設定:從 [開始] 功能表中,選取 [設定> 更新與安全性>復原>重設這部計算機:開始使用。 依照畫面上的指示進行。

  • Windows RE:從 [開始] 功能表中,選取 [設定> 更新與安全性>復原>進階啟動:立即重新啟動。 Windows RE 開機之後,選取 [針對重設這部計算機進行疑難解答>],然後遵循畫面上的指示。

若要測試更多復原選項,請參閱 驗證案例

ScanState 語法

裸機重設/復原:在部署新裝置時建立復原媒體

使用 ScanState 部署按鈕重設功能