Jump to content


Photo

Batch Scripts for ImageX Apply, Capture and Append


  • Please log in to reply
1 reply to this topic

#1 Space Surfer

Space Surfer

    Member

  • Members
  • PipPip
  • 19 posts

Posted 14 June 2007 - 03:33 PM

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 offcd /d %~dp0if not exist "imagex.exe" goto _notexistgoto _main:_notexistecho.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.pauseexit:_mainecho.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 restoredecho        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 _menu1if "%_atarget%" == "" goto _menu1if "%_index%" == "" goto _menu1echo     4) Apply your image now where readyecho        From [%_asource%] To [%_atarget%]echo.:_menu1echo     Q) Quit.    R) Reset all variables.echo.:_mainchset _ok=set /p _ok=Enter your choice: if "%_ok%" == "1" goto _getsrcif "%_ok%" == "2" goto _gettargetif "%_ok%" == "3" goto _getindexif "%_ok%" == "4" goto _applyif /I "%_ok%" == "q" goto _endif /I "%_ok%" == "r" goto _resetgoto _mainch:_getsrcset _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=%%~xAif 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)):_gettargetset _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:_getindexset _ok=echo.echo Specify image index with a numberset /p _ok=Enter Index number: set _index=%_ok%setx _index %_ok%goto _main:_applyecho.echo.@echo onimagex.exe /apply "%_asource%" %_index% "%_atarget%"@echo offecho.pausegoto _end:_resetset _asource=set _index=set _atarget=goto _main:_end

imagex_captureappend.cmd
@echo offcd /d %~dp0if not exist "imagex.exe" goto _notexistgoto _main:_notexistecho.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.pauseexit:_mainif exist "%_ctarget%" set _append=yesif not exist "%_ctarget%" set _append=noif /i "%_append%"=="yes" set function=Appendif /i "%_append%"=="no" set function=Captureecho.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 _menu1if "%_ctarget%" == "" goto _menu1if "%_descript%" == "" goto _menu1if "%_append%" == "yes" goto _skipcaptureif "%_FLAG%" == "" goto _menu1if "%_compr%" == "" goto _menu1:_skipcaptureecho    6) %function% your image now when readyecho       From [%_csource%] To [%_ctarget%]echo.:_menu1echo    Q) Quit.  R) Reset all variablesecho.:_mainchset _ok=set /p _ok=Enter your choice: if "%_ok%" == "1" goto _getsrcif "%_ok%" == "2" goto _gettargetif "%_ok%" == "3" goto _getdescriptif "%_ok%" == "4" goto _getFLAGif "%_ok%" == "5" goto _getcomprif "%_ok%" == "6" goto _captureif /I "%_ok%" == "q" goto _endif /I "%_ok%" == "r" goto _resetgoto _mainch:_getsrcset _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:_gettargetset _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=%%~dpAif /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  ))):_getcomprset comp =echo.echo Please select compression type.echo.echo    1 for MAXIMUMecho    2 for FASTecho    3 for NONEecho.set /p type=Enter compression type: if %type%==1 set _compr=MAXIMUM&& setx _compr MAXIMUMif %type%==2 set _compr=FAST&& setx _compr FASTif %type%==3 set _compr=NONE&& setx _compr NONEgoto _main:_getFLAGset _ok=echo.echo Specify image FLAG (without quotes).echo.set /p _ok=Enter FLAG: set _FLAG=%_ok%setx _FLAG %_ok%goto _main:_getdescriptset _ok=echo.echo Type description of image (without quotes).echo.set /p _ok=Enter description: set _descript=%_ok%setx _descript "%_ok%"goto _main:_captureecho.if "%_append%"=="yes" goto _appendimageecho Ready to capture image from source %_csource% and store image to fileecho %_ctarget% using compression type %_compr%.echo.pauseecho.@echo onimagex.exe /capture "%_csource%" "%_ctarget%" "%_FLAG%" "%_descript%" /COMPRESS %_compr%@echo offpausegoto _end:_appendimageecho.echo Ready to append image from source %_csource% and store image to fileecho %_ctarget%.echo.pauseecho.@echo onimagex.exe /append "%_csource%" "%_ctarget%" "%_descript%"@echo offpauseecho.goto _end:_resetset _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.

#2 ricktendo

ricktendo

    Group: Banned

  • Global Mods
  • 8,624 posts
  • Location:La Ceiba
  • OS:Windows 8 x64

Posted 17 February 2011 - 02:38 AM

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users