@ECHO OFF
CLS
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO.
ECHO Program Mount_TempImage.cmd - 30 nov 2007
ECHO.
ECHO Existing Virtual Drives if any will be CLOSED
ECHO.
ECHO Virtual TEMPDRIVE will be Created to OPEN Existing tempimage.img
ECHO tempimage.img contains XP LocalSource Folders for Copy to USB-stick
ECHO.
ECHO Update USB-stick with Total Commander Synchronize Dirs ....
ECHO.
pause

:_maintemp
set tmpdrive=
set usbtemp=

ECHO Closing Existing Virtual Drives if any ....
VDK.EXE STOP
vdk.exe remove
echo Existing Virtual Drives if any are Closed
ECHO.

:_tempname
echo.
echo Please give TempImage FileName to be Mounted
ECHO.
IF EXIST u_script\FileSel.vbs (
  FOR /F "tokens=*" %%A IN ('CSCRIPT.EXE //NoLogo u_script\FileSel.vbs') DO SET usbtemp=%%A
  if "!usbtemp!" == "" goto _end_quit
) ELSE (
  set /p usbtemp=Enter TempImage FileName - Default is tempimage.img - Quit = q : 
  if /I "!usbtemp!" == "q" goto _end_quit
  if "!usbtemp!" == "" (
     set usbtemp=tempimage.img
  )
)


ECHO Using Existing Tempimage with FileName = !usbtemp!
IF EXIST !usbtemp! (
   VDK.EXE INSTALL
   VDK.EXE DISK 1
   vdk.exe start
   vdk.exe create
   FOR /F  "tokens=1 delims= " %%A in ('VDK.EXE OPEN 0 !usbtemp! /RW ^| FIND /I "FAT32"') DO (
      SET tmpdrive=%%A
   )
   echo.
   echo TempImage File !usbtemp! was Mounted as TEMPDRIVE = !tmpdrive!
   ECHO.
) ELSE (
   echo.
   echo TempImage File !usbtemp! was not found - ERROR *****
   ECHO.
   pause
   goto _tempname
)
if "!tmpdrive!" == "" (
   ECHO Drive Letter of TEMPDRIVE was not found - ERROR *****
   ECHO.
   ECHO Closing Existing Virtual Drives if any ....
   VDK.EXE STOP
   vdk.exe remove
   echo Existing Virtual Drives if any are Closed
   ECHO.
   goto _end_quit
)
if EXIST !tmpdrive!\$WIN_NT$.~LS\nul (
   ECHO Existing XP LocalSource was found in TEMPDRIVE = !tmpdrive!
   ECHO.
) ELSE (
   ECHO XP LocalSource was not found in TEMPDRIVE = !tmpdrive! - ERROR *****
   ECHO.
   ECHO Closing Existing Virtual Drives if any ....
   VDK.EXE STOP
   vdk.exe remove
   echo Existing Virtual Drives if any are Closed
   ECHO.
)

:_end_quit
ECHO.
ECHO END PROGRAM Mount_TempImage.cmd
ECHO.
pause

EXIT
