Jump to content

Recommended Posts

Posted

Here are my working scripts for image capture, append, and apply. These have to be in the same folder as imagex.exe. Some features:

*If you include setx.exe in same folder, it will remember your filename and paths if you were to close the command prompt and reopen the script.

*Menu-like interface to make it easy to see what is being captured/applied and where to.

*When capturing, it you specify a WIM file that already exists, it will warn you that it will append to that image. If the file does not exist, then it will create a new one.

*When applying an image, if you choose a file name that doesn't exist, it will ask you to reenter the filename. This way, you won't have to retype the whole imagex command!

imagex_apply.cmd

@echo off
cd /d %~dp0
if not exist "imagex.exe" goto _notexist
goto _main
:_notexist
echo.
echo IMAGEX.EXE executable not found. Please ensure that IMAGEX_APPLY.CMD
echo is in the same folder as IMAGEX.EXE before executing this script.
echo This script will now exit.
echo.
pause
exit

:_main
echo.
echo.
echo.
echo [I M A G E X A P P L Y M A I N M E N U]
echo.
echo 1) Specify or change source path (the path to you .wim image file)
echo Source: [%_asource%]
echo.
echo 2) Specify or change target path, where your image will be restored
echo Target: [%_atarget%]
echo.
echo 3) Specify or change index you want to restore (a number, such as 2)
echo Index: [%_index%]
echo.
if "%_asource%" == "" goto _menu1
if "%_atarget%" == "" goto _menu1
if "%_index%" == "" goto _menu1
echo 4) Apply your image now where ready
echo From [%_asource%] To [%_atarget%]
echo.

:_menu1
echo Q) Quit. R) Reset all variables.
echo.

:_mainch
set _ok=
set /p _ok=Enter your choice:
if "%_ok%" == "1" goto _getsrc
if "%_ok%" == "2" goto _gettarget
if "%_ok%" == "3" goto _getindex
if "%_ok%" == "4" goto _apply
if /I "%_ok%" == "q" goto _end
if /I "%_ok%" == "r" goto _reset
goto _mainch

:_getsrc
set _ok=
echo.
echo Specify location of source image to restore with full path.
set /p _ok=Enter Source path:
for %%A in (%_ok%) do set _ext=%%~xA
if not exist %_ok% (
echo.
echo ---------------------------------------------------------
echo Path does not exist. Please input a valid location again.
echo ---------------------------------------------------------
goto _getsrc
) else (
if /I "%_ext%"==".wim" (
set _asource=%_ok%
setx _asource %_ok%
goto _main
) else (
echo.
echo ---------------------------------------------------------------
echo Error: The path "%_ok%" does not seem to be a valid .wim image file.
echo ---------------------------------------------------------------
goto _getsrc
)
)

:_gettarget
set _ok=
echo.
echo Specify target to install source image with full path.
set /p _ok=Enter Target path:
if exist "%_ok%" (
set _atarget=%_ok%
setx _atarget %_ok%
) else (
echo.
echo ---------------------------------------------------------------
echo Error: The path "%_ok%" is not a correct location.
echo ---------------------------------------------------------------
goto _gettarget
)

goto _main

:_getindex
set _ok=
echo.
echo Specify image index with a number
set /p _ok=Enter Index number:
set _index=%_ok%
setx _index %_ok%
goto _main

:_apply
echo.
echo.
@echo on
imagex.exe /apply "%_asource%" %_index% "%_atarget%"
@echo off
echo.
pause
goto _end

:_reset
set _asource=
set _index=
set _atarget=
goto _main

:_end

imagex_captureappend.cmd

@echo off
cd /d %~dp0
if not exist "imagex.exe" goto _notexist
goto _main

:_notexist
echo.
echo IMAGEX.EXE executable not found. Please ensure that imagex_capture.cmd
echo is in the same folder as IMAGEX.EXE before executing this script.
echo This script will now exit.
echo.
pause
exit

:_main
if exist "%_ctarget%" set _append=yes
if not exist "%_ctarget%" set _append=no
if /i "%_append%"=="yes" set function=Append
if /i "%_append%"=="no" set function=Capture
echo.
echo.
echo [I M A G E X C A P T U R E / A P P E N D M A I N M E N U]
echo.
echo 1) Specify or change source path, the path you want to capture (e.g. C:\)
echo Source: [%_csource%]
echo.
echo 2) Specify or change target image to create/append (e.g. d:\myimage.wim)
if "%_append%"=="yes" echo *Image will be appended unless you specify a non-existing image file.*
echo Target: [%_ctarget%]
echo.
echo 3) Specify or change unique description of your image (e.g. Vista Backup)
echo Description: [%_descript%]
echo.
echo 4) Specify or change FLAG of your image (e.g. ULTIMATE)
echo FLAG: [%_FLAG%]
echo.
echo 5) Specify or change compression type (MAXIMU, FAST, NONE)
echo Compression: [%_compr%]
echo.
if "%_csource%" == "" goto _menu1
if "%_ctarget%" == "" goto _menu1
if "%_descript%" == "" goto _menu1
if "%_append%" == "yes" goto _skipcapture
if "%_FLAG%" == "" goto _menu1
if "%_compr%" == "" goto _menu1
:_skipcapture
echo 6) %function% your image now when ready
echo From [%_csource%] To [%_ctarget%]
echo.

:_menu1
echo Q) Quit. R) Reset all variables
echo.

:_mainch
set _ok=
set /p _ok=Enter your choice:
if "%_ok%" == "1" goto _getsrc
if "%_ok%" == "2" goto _gettarget
if "%_ok%" == "3" goto _getdescript
if "%_ok%" == "4" goto _getFLAG
if "%_ok%" == "5" goto _getcompr
if "%_ok%" == "6" goto _capture
if /I "%_ok%" == "q" goto _end
if /I "%_ok%" == "r" goto _reset
goto _mainch


:_getsrc
set _ok=
echo.
echo Specify location of source to capture as a .wim image.
echo Usually, this would be the root of a drive, such as C:\.
echo.
set /p _ok=Enter Source path:
if exist "%_ok%" (
setx _csource %_ok%
set _csource=%_ok%
) else (
echo.
echo ---------------------------------------
echo Error: The path "%_ok%" does not exist.
echo ---------------------------------------
goto _getsrc
)

goto _main

:_gettarget
set _ok=
echo.
echo Specify path and filename to store the target image, such as D:\image.wim.
echo.
set /p _ok=Enter Target image path:
for %%A in (%_ok%) do set _ext=%%~xA && set _path=%%~dpA
if /I not "%_ext%"==".wim " (
echo.
echo -----------------------------------------------------
echo Error: The filename entered is not a valid .wim file.
echo -----------------------------------------------------
goto _gettarget
) else (
if exist %_ok% (
set _ctarget=%_ok%
setx _ctarget %_ok%
set _append=yes
setx _append yes
goto _main
) else (
if not exist %_path% (
echo.
echo -----------------------------------------------------
echo Path does not exist. Please input a valid path again.
echo -----------------------------------------------------
goto _gettarget
) else (
setx _ctarget %_ok%
set _ctarget=%_ok%
set _append=no
setx _append no
goto _main
)
)
)

:_getcompr
set comp =
echo.
echo Please select compression type.
echo.
echo 1 for MAXIMUM
echo 2 for FAST
echo 3 for NONE
echo.
set /p type=Enter compression type:
if %type%==1 set _compr=MAXIMUM&& setx _compr MAXIMUM
if %type%==2 set _compr=FAST&& setx _compr FAST
if %type%==3 set _compr=NONE&& setx _compr NONE

goto _main

:_getFLAG
set _ok=
echo.
echo Specify image FLAG (without quotes).
echo.
set /p _ok=Enter FLAG:
set _FLAG=%_ok%
setx _FLAG %_ok%

goto _main

:_getdescript
set _ok=
echo.
echo Type description of image (without quotes).
echo.
set /p _ok=Enter description:
set _descript=%_ok%
setx _descript "%_ok%"
goto _main

:_capture
echo.
if "%_append%"=="yes" goto _appendimage
echo Ready to capture image from source %_csource% and store image to file
echo %_ctarget% using compression type %_compr%.
echo.
pause
echo.
@echo on
imagex.exe /capture "%_csource%" "%_ctarget%" "%_FLAG%" "%_descript%" /COMPRESS %_compr%
@echo off
pause
goto _end

:_appendimage
echo.
echo Ready to append image from source %_csource% and store image to file
echo %_ctarget%.
echo.
pause
echo.
@echo on
imagex.exe /append "%_csource%" "%_ctarget%" "%_descript%"
@echo off
pause
echo.
goto _end

:_reset
set _csource=
set _ctarget=
set _descript=
set _compr=
set _FLAG=
set _append=
goto _main

:_end

setx.exe is part of MS Support Tools

Report any bugs to me. Thanks.

  • 3 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...