使用 DISM 離線新增或移除套件Add or Remove Packages Offline Using DISM

部署映射服務與管理 ( # A0) 是一種命令列工具,可用來更新離線 Windows®映射。Deployment Image Servicing and Management (DISM.exe) is a command-line tool that is used to update offline Windows® images. 有兩種方式可以使用 DISM 離線安裝或移除套件。There are two ways to install or remove packages offline with DISM. 您可以將自動安裝回應檔案套用到離線映射,也可以直接從命令提示字元新增或移除封裝。You can either apply an unattend answer file to the offline image, or you can add or remove the package directly from the command prompt.

如果您要將多個套件安裝到 Windows 映像,而且有相依性需求,最好的方式是使用回應檔案來確保安裝的正確順序。If you are installing multiple packages to a Windows image, and there are dependency requirements, the best way to ensure the correct order of the installation is by using an answer file. 您可以使用 DISM 將 Unattend.xml 回應檔案套用至映射。You can use DISM to apply the Unattend.xml answer file to the image. 當您使用 DISM 套用回應檔案時, offlineServicing 設定階段中的自動安裝設定會套用至 Windows 映像。When you use DISM to apply an answer file, the unattend settings in the offlineServicing configuration pass are applied to the Windows image.

您必須將最新版本的 Windows 評定及部署套件安裝 (Windows ADK) ,其中包含所有必要的工具,包括 DISM。You must install the latest version of the Windows Assessment and Deployment Kit (Windows ADK), which contains all of the tools that are required, including DISM.

使用 DISM 將封裝新增至離線映射To add packages to an offline image by using DISM

  1. 在提高許可權的命令提示字元中,找出 [Windows ADK 服務] 資料夾,並輸入下列命令,以抓取您要修改之映射的名稱或索引編號。At an elevated command prompt, locate the Windows ADK servicing folder, and type the following command to retrieve the name or index number for the image that you want to modify.

    Dism /Get-ImageInfo /ImageFile:C:\test\images\install.wim
    

    指定影像檔案的大部分作業都需要索引或名稱值。An index or name value is required for most operations that specify an image file.

  2. 輸入下列命令以掛接離線 Windows 映像。Type the following command to mount the offline Windows image.

    Dism /Mount-Image /ImageFile:C:\test\images\install.wim /Name:"Windows 7 HomeBasic" /MountDir:C:\test\offline
    
  3. 在命令提示字元中輸入下列命令,將特定套件新增至映射。At a command prompt, type the following command to add a specific package to the image. 您可以在一個命令列上新增多個封裝。You can add multiple packages on one command line. 系統會依命令列中所列的順序來安裝它們。They will be installed in the order listed in the command line.

    Dism /Image:C:\test\offline /Add-Package /PackagePath:C:\packages\package1.cab /PackagePath:C:\packages\package2.cab
    
  4. 在命令提示字元中,輸入下列命令來認可變更並卸載映射。At a command prompt, type the following command to commit the changes and unmount the image.

    Dism /Unmount-Image /MountDir:C:\test\offline /Commit
    

使用 DISM 從離線映射移除套件To remove packages from an offline image by using DISM

  1. 在提高許可權的命令提示字元中,找出 [Windows ADK 服務] 資料夾,並輸入下列命令,以抓取您要修改之映射的名稱或索引編號。At an elevated command prompt, locate the Windows ADK servicing folder, and type the following command to retrieve the name or index number for the image that you want to modify.

    Dism /Get-ImageInfo /ImageFile:C:\test\images\install.wim
    

    指定影像檔案的大部分作業都需要索引或名稱值。An index or name value is required for most operations that specify an image file.

  2. 輸入下列命令以掛接離線 Windows 映像。Type the following command to mount the offline Windows image.

    Dism /Mount-Image /ImageFile:C:\test\images\install.wim /Name:"Windows 7 HomeBasic" /MountDir:C:\test\offline
    
  3. 選用:輸入下列命令以列出映射中的套件。Optional: Type the following command to list the packages in the image.

    Dism /Image:C:\test\offline /Get-Packages
    

    您可以使用 >featurelist.txt 將命令的輸出重新導向至名為 FeatureList 的文字檔。You can use >featurelist.txt to redirect the output of the command to a text file that is named FeatureList.

  4. 檢查您的已掛接映射中可用的套件清單,並記下套件的封裝身分識別。Review the list of packages that are available in your mounted image and note the package identity of the package.

  5. 在命令提示字元中,指定要從映射中移除的套件識別。At a command prompt, specify the package identity to remove it from the image. 您可以在一個命令列上移除多個封裝。You can remove multiple packages on one command line.

    DISM /Image:C:\test\offline /Remove-Package /PackageName:Microsoft.Windows.Calc.Demo~6595b6144ccf1df~x86~en~1.0.0.0 /PackageName:Microsoft-Windows-MediaPlayer-Package~31bf3856ad364e35~x86~~6.1.6801.0
    

    您可以使用 /packagepath 選項指向封裝的原始來源,或指定 .cab 檔案的路徑,或者您可以使用 [ /packagename ] 選項,依名稱指定封裝(如影像中所列)。You can use the /PackagePath option to point to the original source of the package, or to specify the path to the .cab file, or you can use the /PackageName option to specify the package by name as it is listed in the image. 如需詳細資訊,請參閱 DISM 作業系統套件服務命令列選項For more information, see DISM Operating System Package Servicing Command-Line Options.

  6. 在命令提示字元中,輸入下列命令來認可變更並卸載映射。At a command prompt, type the following command to commit the changes and unmount the image.

    Dism /Unmount-Image /MountDir:C:\test\offline /Commit
    

使用 DISM 和回應檔案離線新增或移除套件To add or remove packages offline by using DISM and an answer file

  1. 開啟 Windows SIM。Open Windows SIM.

  2. 若要加入新的封裝,請按一下主功能表上的 [ 插入 ],然後選取 [ 封裝 (s)To add a new package, click Insert on the main menu, and select Package(s). 流覽至您要新增的封裝,然後按一下 [ 開啟]。Browse to the package you want to add, and then click Open.

  3. 若要移除現有的封裝,請在 [ 回應 檔案] 窗格中選取您想要移除的套件。To remove an existing package, select the package in the Answer file pane that you want to remove. 在 [ 屬性 ] 窗格中,將 [ 動作 ] 屬性變更為 [ 移除]。In the Properties pane, change the Action property to Remove.

    注意Note
    必須將套件新增至 offlineServicing 設定階段。The packages must be added to the offlineServicing configuration pass.

  4. 驗證並儲存回應檔案。Validate and save the answer file.

  5. 在提高許可權的命令提示字元中,找出 [Windows ADK 服務] 資料夾,然後輸入下列命令,以抓取您要掛接之映射的名稱或索引編號。At an elevated command prompt, locate the Windows ADK servicing folder, and then type the following command to retrieve the name or index number for the image that you want to mount.

    Dism /Get-ImageInfo /ImageFile:C:\test\images\install.wim
    
  6. 輸入下列命令以掛接離線 Windows 映像。Type the following command to mount the offline Windows image.

    Dism /Mount-Image /ImageFile:C:\test\images\install.wim /name:"Windows 7 HomeBasic" /MountDir:C:\test\offline
    

    指定影像檔案的大部分作業都需要索引或名稱值。An index or name value is required for most operations that specify an image file.

  7. 在命令提示字元中,輸入下列命令以將自動回應檔案套用至映射。At a command prompt, type the following command to apply the unattended answer file to the image.

    DISM /Image:C:\test\offline /Apply-Unattend:C:\test\answerfiles\myunattend.xml
    
  8. 在命令提示字元中,輸入下列命令來認可變更並卸載映射。At a command prompt, type the following command to commit the changes and unmount the image.

    Dism /Unmount-Image /MountDir:C:\test\offline /Commit
    

如需 Windows SIM 的詳細資訊,請參閱 Windows 安裝程式技術參考For more information about Windows SIM, see Windows Setup Technical Reference.

相關主題Related topics

DISM - Windows 的部署映像維護與管理技術參考DISM - Deployment Image Servicing and Management Technical Reference for Windows

DISM 作業系統套件服務命令列選項DISM Operating System Package Servicing Command-Line Options

DISM 自動維護命令列選項DISM Unattended Servicing Command-Line Options