DISM命令使用小结
操作WIM镜像
说明
REM 制作镜像并添加一个分卷
dism /capture-image /imagefile:<WIM镜像路径> /captureDir:<备份目录> /name:<分卷名称> [/description:<分卷描述>]
REM 在镜像中添加一个分卷
dism /append-image /imagefile:<WIM镜像路径> /captureDir:<备份目录> /name:<分卷名称> [/description:<分卷描述>]
REM 在镜像中删除一个分卷(可能会修改所有分卷的索引)
dism /delete-image /imagefile:<WIM镜像路径> /Index:<分卷索引>
REM 从镜像中导出一个分卷成为新的镜像
dism /export-image /sourceimageFile:<源WIM镜像路径> /sourceindex:<分卷索引> /destinationimagefile:<新WIM镜像路径>
REM 查看镜像分卷信息
dism /get-imageinfo /imagefile:<WIM镜像路径>
REM 查看镜像一个分卷的文件内容
dism /list-image /imagefile:<WIM镜像路径> /index:<分卷索引>
REM 挂载镜像
dism /mount-wim /wimfile:<WIM镜像路径> /index:<分卷索引> /mountdir:<挂载目录> [/readonly]
REM 卸载镜像并放弃修改
dism /unmount-wim /mountdir:<挂载目录> /discard
REM 卸载镜像并保存修改
dism /unmount-wim /mountdir:<挂载目录> /commit
REM 使用镜像恢复目录
dism /apply-image /imagefile:<WIM镜像路径> /index:<分卷索引> /applydir:<恢复目录>
演示
REM 以管理员身份运行CMD
MKDIR "%Temp%\DismDemo" 2>NUL
PUSHD "%Temp%\DismDemo"
MKDIR package
MKDIR mounted
REM 首次创建
ECHO first>package\test.txt
dism /capture-image /imagefile:test.wim /captureDir:package /name:1st /description:第一次>NUL
REM 添加镜像
ECHO second>package\test.txt
dism /append-image /imagefile:test.wim /captureDir:package /name:2nd /description:第二次>NUL
ECHO third>package\test.txt
dism /append-image /imagefile:test.wim /captureDir:package /name:3rd /description:第三次>NUL
REM 查看分卷文件
dism /list-image /imagefile:test.wim /index:1
REM 查看镜像分卷
dism /get-imageinfo /imagefile:test.wim
REM 挂载镜像并查看记录的内容
dism /mount-wim /wimfile:test.wim /index:1 /mountdir:mounted /readonly>NUL
type mounted\test.txt
dism /unmount-wim /mountdir:mounted /discard>NUL
REM 使用镜像恢复目录
type package\test.txt
dism /apply-image /imagefile:test.wim /index:2 /applydir:package>NUL
type package\test.txt
REM 挂载镜像并修改记录的内容
dism /mount-wim /wimfile:test.wim /index:2 /mountdir:mounted>NUL
ECHO second changed>mounted\test.txt
dism /unmount-wim /mountdir:mounted /commit>NUL
dism /mount-wim /wimfile:test.wim /index:2 /mountdir:mounted /readonly>NUL
type mounted\test.txt
dism /unmount-wim /mountdir:mounted /discard>NUL
REM 删除一个分卷
dism /delete-image /imagefile:test.wim /Index:1>NUL
dism /get-imageinfo /imagefile:test.wim
REM 导出一个分卷
dism /export-image /sourceimageFile:test.wim /sourceindex:1 /destinationimagefile:new.wim>NUL
dism /get-imageinfo /imagefile:new.wim
POPD
RMDIR /S /Q "%Temp%\DismDemo"
挂载同名文件.wim
@ECHO OFF
MKDIR %SystemRoot%\testauth 2>nul && RMDIR %SystemRoot%\testauth || echo "Please run as administrator!" && PAUSE && GOTO :EOF
ECHO mounting...
CD /d %~dp0
SET MYNAME=%~n0
IF NOT EXIST %MYNAME%.wim GOTO :EOF
IF EXIST %MYNAME% (
DISM /unmount-wim /mountdir:"%MYNAME%" /discard
RMDIR %MYNAME%
) ELSE (
MKDIR %MYNAME%
DISM /mount-wim /wimfile:"%MYNAME%.wim" /mountdir:"%MYNAME%" /index:1 /readonly
)
操作系统映像
说明
REM 以正在运行的操作系统为目标 | 指定脱机映像的根目录路径
dism { /online | /image:<镜像挂载到的地址> } ...
REM 通过扫描来查找映像中的组件存储损坏
dism /online /cleanup-image { /checkhealth | /scanhealth | /restorehealth }
REM 获取当前系统驱动列表
dism /online /get-drivers
REM 获取当前系统功能列表
dism /online /get-features /format:table
REM 启用当前系统功能
dism /online enable-feature /featurename:<功能名称> /all
添加功能
DIR /b %SystemRoot%\servicing\Packages
启用本地策略
若不能启动gpedit.msc
,则以管理员身份运行一个命令窗口,输入以下内容:
@ECHO OFF
SET PACKAGES_LOCATION=%SystemRoot%\servicing\Packages
SET ENABLE_LIST="%Temp%\PACKAGES%RANDOM%%RANDOM%.txt"
REM ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
DIR /b %PACKAGES_LOCATION%\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum>%ENABLE_LIST%
DIR /b %PACKAGES_LOCATION%\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum>>%ENABLE_LIST%
REM ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
FOR /F %i in ('FINDSTR /I . %ENABLE_LIST% 2^>NUL') DO (
echo %i
dism /online /norestart /add-package:"%PACKAGES_LOCATION%\%i">NUL
)
DEL /F /Q %ENABLE_LIST%
ECHO Done!
启用Hyper-V
dism /online /get-features /format:table | findstr /i Hyper-V
@ECHO OFF
SET PACKAGES_LOCATION=%SystemRoot%\servicing\Packages
SET ENABLE_LIST="%Temp%\PACKAGES%RANDOM%%RANDOM%.txt"
REM ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
DIR /b %PACKAGES_LOCATION%\Microsoft-Hyper-V-*.mum>%ENABLE_LIST%
REM ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
FOR /F %i in ('FINDSTR /I . %ENABLE_LIST% 2^>NUL') DO (
echo %i
dism /online /norestart /add-package:"%PACKAGES_LOCATION%\%i">NUL
)
DEL /F /Q %ENABLE_LIST%
dism /online /norestart /enable-feature /featurename:Microsoft-Hyper-V-All /all
ECHO Done!