spacesurfer Posted June 1, 2007 Posted June 1, 2007 (edited) Thanks for everyone's help below. I've edited this post.The batch scripts are below.This will allow you to make sure you are entering the paths correctly with all the switches necessary.Links: Imagex_apply.cmd, imagex_captureapply.cmd Edited June 7, 2007 by spacesurfer
geezery Posted June 1, 2007 Posted June 1, 2007 @echo offset comp =echo 1 for maximumecho 2 for fastecho 3 for noneecho " "set /p type=Enter compression type: if %type%==1 set comp=maximumif %type%==2 set comp=fastif %type%==3 set comp=noneecho %comp%
spacesurfer Posted June 1, 2007 Author Posted June 1, 2007 Got it working. Thanks for help, Geezery.Another question if you can help:I want to check whether the folder where the new image will reside exists or not. For example, I tell my script I want image in D:\Images\Image.wim; how would I get it to check that D:\Images\ exists or not (just in case there was error and so I wouldn't have to repeat the whole process)? It would mean I'd have to delete Images.wim from the variable assigned to the whole D:\Images\Images.wim.Is this possible?Appreciate your help.
IcemanND Posted June 1, 2007 Posted June 1, 2007 for %A in (%MyImage%) do if not Exist %~dpA goto GetPath
spacesurfer Posted June 1, 2007 Author Posted June 1, 2007 (edited) @IcemanND, I couldn't get it to work. I even replaced %A to %%A (for some reason I've seen that before). The %~dpA expands to a 0.Anyway, here are my working scripts for image capture and image apply. These have to be in the same folder as imagex.exe. It just won't check your path to see whether it is correct or not since I couldn't get it to work.(I understand someone is working on or has made a GUI but this fits my purposes.)imagex_apply.cmd imagex_capture.cmdimagex_apply.cmd@echo offcd /d %~dp0set imgx=%cd%if not exist "%cd%\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 pause)):_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 pause)goto _main:_getindexset _ok=echo.echo Specify image index with numberset /p _ok=Enter Index number: set _index=%_ok%setx _index %_ok%goto _main:_applyecho.echo."%imgx%\imagex.exe" /apply "%_asource%" %_index% "%_atarget%"echo.pausegoto _end:_resetset _asource=set _index=set _atarget=goto _main:_endimagex_captureappend.cmd@echo offcd /d %~dp0set imgx=%cd%if not exist "%cd%\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:_mainecho.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 (maximum, fast, none)echo Compression: [%_compr%]echo.if "%_csource%" == "" goto _menu1if "%_ctarget%" == "" goto _menu1if "%_descript%" == "" goto _menu1if "%_append%" == "yes" goto _skipif "%_FLAG%" == "" goto _menu1if "%_compr%" == "" goto _menu1:_skipecho 6) Capture or append 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 pause)goto _main:_gettargetset targ=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 "%_ext%"==" " ( 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.echo.set /p _ok=Enter FLAG: set _FLAG=%_ok%setx _FLAG %_ok%goto _main:_getdescriptset _ok=echo.echo Type description of imageecho.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 toecho %_ctarget% using compression type %_compr%.echo.pauseecho.echo on"%imgx%\imagex.exe" /capture %_csource% "%_ctarget%" "%_FLAG%" "%_descript%" /COMPRESS %_compr%echo offpausegoto _end:_appendimageecho.echo Ready to append image from source %_csource% and store image toecho %_ctarget%.echo.pauseecho.echo on"%imgx%\imagex.exe" /append %_csource% "%_ctarget%" "%_descript%"echo offpauseecho.goto _end:_reset@echo offset _csource=set _ctarget=set _descript=set _compr=set _FLAG=set _append=goto _main:_endEdit: If you don't have setx, download from link provided by FireGeier in one of the following post. setx is not necessary. If you don't have it, you can delete the lines that point to setx and script will still work, but it won't remember your paths when you restart the script.Edit2: Corrected some bugs. Added append if you point to an existing .wim file. Edited June 11, 2007 by Shark007 change code tags to codebox
IcemanND Posted June 2, 2007 Posted June 2, 2007 for use in a batch file:for %%A in (%_ok%) do if Exist %%~dpA ( set _target=%_ok%) else ( echo. echo Error: The path "%_ok%" does not exist. goto _settarget pause)set _targetpausehow's that for 1.5k in posts.
FireGeier Posted June 2, 2007 Posted June 2, 2007 Hello spacesurfer!You can check for NUL, if you want to find out, if folder does exist:IF EXIST D:\Images\NUL your command, if D:\Images does existORIF NOT EXIST D:\Images\NUL your command, if D:\Images does NOT existRegards,Martin
spacesurfer Posted June 5, 2007 Author Posted June 5, 2007 (edited) IcemanND, your script does check for the folder, but it will accept a folder without a filename specified whether it exists or not.For example, if I input F:\windows\myimage, it will tell me F:\windows does not exist (in case it really doesn't exist).On the other hand, if I input F:\windows\, it will take it (even though F:\windows\ does not exist).I thought that was strange.Addendum:I got it working IcemanND.But now the question is, is there a way to save the variables (to the paths) you entered and recall them next time you run the script after closing the command prompt? Edited June 6, 2007 by spacesurfer
FireGeier Posted June 6, 2007 Posted June 6, 2007 Hello spacesurfer!You can use setx command to save variables to system envrionment. setx is included in Vista. For XP you need to extract setx from MS Support Tools for XP Service Pack 2.Syntax:setx variable value (-m)-m is optional, it will set the variable to machine environment.Without -m it's set to users environment.Regards,Martin
jaclaz Posted June 6, 2007 Posted June 6, 2007 Just for the record, the proper way to check for a directory should be checking for nul.ext instead of nul, at least on NT based systems, reference:http://xset.tripod.com/tip5.htmhttp://msmvps.com/blogs/martinzugec/archiv...-same-name.aspxIt is a remote possibility that there exists a file with same name as folder, but you never know.jaclaz
spacesurfer Posted June 6, 2007 Author Posted June 6, 2007 @FireGeier. Thanks for setx. I got it working nowBut I had to use both set and setx. Reason is setx didn't seem to update the variables in the menu (so I wasn't sure if they were being assigned in real time). If I closed and restarted, then I saw the variables.Also if I changed an already assigned variable with setx, then I had to restart the script to see the change.I got around it by using both commands and it works fine.Thanks for tip.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now