|
- @echo off
- title WIM简易修改工具
- ::此工具必须以管理员权限运行
- color 3f
- rem 自动请求以管理员权限运行
- echo CreateObject^("Shell.Application"^).ShellExecute "%~f0", "", "", "runas", 1 > "%temp%\getadmin.vbs"
- reg query HKU\S-1-5-20>nul 2>nul||cscript //b "%temp%\getadmin.vbs"&&del "%temp%\getadmin.vbs" /f /q>nul 2>nul&&exit /b
- pushd %~dp0\
- setlocal enabledelayedexpansion
- :filesel
- ::智能文件选择列表
- ::只有1个文件时自动选中,大于1≤100列表文件,>100则不再列表,改为手动输入;选择错误会自动返回选择菜单。
- ::列表菜单 空格键翻页,Q结束翻页
- cls
- for /f %%a in ('dir /a /b *.wim 2^>nul ^| find /c /n /v ""') do set filenum=%%a
- if %filenum% equ 0 (echo 错误:未找到文件... & pause>nul & goto filesel)
- if %filenum% gtr 100 (
- echo 当前文件数目大于100,列表已带来不了多少便利
- echo 请输入文件路径:
- set /p wimfile=
- set wimfile=!wimfile:"=!
- cls & goto menu
- )
- if %filenum% equ 1 (set select=1) else dir /a /b *.wim | find /n /v "" | more & set /p select=请选择文件:
- if %select% lss 1 echo 只能输入 1 - %filenum% 之间的数字 && pause>nul && goto filesel
- if %select% gtr %filenum% echo 只能输入 1 - %filenum% 之间的数字 && pause>nul && goto filesel
- set /a var=%select%-1
- if not %var% leq 0 (set "skip=skip=%var% ") else set skip=
- for /f "%skip%delims=" %%b in ('dir /a /b *.wim ^| find /v ""') do (
- set "wimfile=%%~fb"
- cls & goto menu
- )
- :menu
- if not defined wimfile goto filesel
- title WIM简易修改工具,文件:%wimfile%
- echo.
- echo 菜单
- echo ━━
- echo.
- echo 1.装载映像 2.卸载映像,保存更改
- echo.
- echo 3.导出映像 4.卸载映像,放弃更改
- echo.
- echo 5.恢复孤立的映像装载目录
- echo.
- echo 0.清屏
- echo.
- set /p input=请选择您要执行的操作:
- echo.
- echo.
- if %input%==1 goto mount else goto menu
- if %input%==2 goto unmount-commit else goto menu
- if %input%==3 goto export-image else goto menu
- if %input%==4 goto unmount-discard else goto menu
- if %input%==5 goto remount else goto menu
- if %input%==0 cls&goto menu else goto menu
- cls&goto menu
- :mount
- echo ·装载映像...
- echo.
- attrib -r "%wimfile%" >nul 2>nul
- dism /mount-wim /wimfile:"%wimfile%" /index:1 /mountdir:pe
- goto menu
- :unmount-commit
- echo ·卸载映像,保存更改...
- echo.
- dism /unmount-wim /mountdir:pe /commit
- goto menu
- :unmount-discard
- echo ·卸载映像,放弃更改...
- echo.
- dism /unmount-wim /mountdir:pe /discard
- goto menu
- :export-image
- echo ·导出映像...
- echo.
- dism /export-image /sourceimagefile:"%wimfile%" /sourceindex:1 /destinationimagefile:"%wimfile%.bak" /checkintegrity /compress:max
- if exist "%wimfile%.bak" (del /f /q "%wimfile%") else (goto menu)
- move "%wimfile%.bak" "%wimfile%" >nul
- goto menu
- :remount
- echo ·恢复孤立的映像装载目录...
- echo.
- dism /remount-image /mountdir:pe
- goto menu
复制代码 |
|