使用 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