Help required with DOS Batch File

August 13, 2010 at 12:07:53
Specs: Windows XP
I need help with the below batch file. If I select choice #1, it executes the task & automatically goes to the second choice instead of exiting. To exit, I need to cancel the second choice. Please advice on modification so that it goes to exit directly after executing choice #1.

@ECHO OFF
ECHO.

ECHO =============== Host PC Restore Disk ===============
ECHO.
ECHO.
ECHO Please choose one of the following:
ECHO.

ECHO 1 - Restore Disk C only (will preserve data on Disk D)
ECHO.
ECHO 2 - Restore Disk D only (will erase data on Disk D)
ECHO.
ECHO 3 - Exit without Restoring
ECHO.

ECHO.

CHOICE /C:123

IF errorlevel 3 goto EXIT
IF errorlevel 2 goto DSKD
IF errorlevel 1 goto DSKC

:DSKC
ECHO.
ECHO Disk C will be Restored now
ECHO.
path=a:\;x:\
MOUSE.COM
OHCI.EXE
UHCI.EXE
mscdex.exe /d:DVDROM /l:x /m:16 /v
x:
ghost.exe -clone,mode=pload,src=%DVDROM%\DSKC.GHO:1,dst=1:1
ECHO.
PAUSE
CLS
EXIT

:DSKD
ECHO.
ECHO Disk D will be Restored now
ECHO.
path=a:\;x:\
MOUSE.COM
OHCI.EXE
UHCI.EXE
mscdex.exe /d:DVDROM /l:x /m:16 /v
x:
ghost.exe -clone,mode=pload,src=%DVDROM%\DSKD.GHO:1,dst=1:2
ECHO.
PAUSE
CLS
EXIT

:EXIT
ECHO.
ECHO Exiting Restore Operation
ECHO.
PAUSE
CLS
EXIT


See More: Help required with DOS Batch File

Report •

#1
August 13, 2010 at 17:29:14
I personally don't use choice, so here is how I would write your code.

@ECHO OFF
ECHO.

ECHO =============== Host PC Restore Disk ===============
ECHO.
ECHO.
ECHO Please choose one of the following:
ECHO.

ECHO 1 - Restore Disk C only (will preserve data on Disk D)
ECHO.
ECHO 2 - Restore Disk D only (will erase data on Disk D)
ECHO.
ECHO 3 - Exit without Restoring
ECHO.

ECHO.

ECHO Enter the number of your choice:
SET /p Choice=""
IF "%Choice%"=="1" GOTO DSKC
IF "%Choice%"=="2" GOTO DSKD
IF "%Choice%"=="3" GOTO EXIT

:DSKC
ECHO.
ECHO Disk C will be Restored now
ECHO.
path=a:\;x:\
MOUSE.COM
OHCI.EXE
UHCI.EXE
mscdex.exe /d:DVDROM /l:x /m:16 /v
x:
ghost.exe -clone,mode=pload,src=%DVDROM%\DSKC.GHO:1,dst=1:1
ECHO.
PAUSE
CLS
EXIT

:DSKD
ECHO.
ECHO Disk D will be Restored now
ECHO.
path=a:\;x:\
MOUSE.COM
OHCI.EXE
UHCI.EXE
mscdex.exe /d:DVDROM /l:x /m:16 /v
x:
ghost.exe -clone,mode=pload,src=%DVDROM%\DSKD.GHO:1,dst=1:2
ECHO.
PAUSE
CLS
EXIT

:EXIT
ECHO.
ECHO Exiting Restore Operation

ECHO.
PAUSE
CLS
EXIT


Report •

#2
August 14, 2010 at 00:11:33
[1] You didn't say what version of DOS.

[2] The only thing that ocurs to me is that one or more of the EXEs within the :DSKC block is loading another command shell so your EXIT exits that shell and the bat runs right along.

Try this:

=============================

:DSKC
rem do EXEs
goto :end

:DSKD
rem do EXEs
goto :end

:end


=====================================
Helping others achieve escape felicity

M2


Report •

#3
August 14, 2010 at 00:20:52
Matt123,

There is no set /p in DOS.

If it was XP, MSCDEX wouldn't do anything very useful.

I'll stay tuned.


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
August 14, 2010 at 07:38:11
Ahh, that is true.

My apologies ntj888. I didn't actually read over all of your code, Just a quick scan to see if you were missing any "GOTO's" or anything similar


Report •

#5
August 15, 2010 at 12:17:13
Version of DOS is 5.0.
As you've seen, I'm trying to restore disk partitions using Norton Ghost from a bootable DVD. The batch file is the autoexec.bat file in the boot section of the DVD.

Report •

#6
August 15, 2010 at 12:47:53
Did you implement Mechanix2Go's suggestion? "Goto end" is how I used to end batch files, and I don't think it was because I was too lazy to type "exit" (too many years to really remember, and all that).

Report •

Ask Question