...

View Full Version : batch goto issue



dw5304
05-13-2007, 01:32 AM
im working on getting a batch file for a autoinstall after windows installes its self.

for updates and open office.
i have got everything done except the goto dose not work.

this is what i have so far.


@echo on
@set /P SDDRIVELETTER=Please enter the driveletter for your flash drive:
@cd %SDDRIVELETTER%:\
@pause
@if exist C:\office.txt goto error
@if not exist C:\office.txt goto office
@:error
@echo office is allready installed
@goto update
@:office
@set /P YESNO=do u want to install open office(y/n):
@If /I %YESNO% == 'y' then goto setup
@pause
@:update
@echo running updates>>C:\updates.txt
@if exist C:\1.txt goto 2
@echo running kb00001>>C:\1.txt
@goto 2
@:2
@if exist C:\2.txt goto 3
@echo running kb00002>>C:\2.txt
@echo Windows Registry Editor Version 5.00 >>C:\test.reg
@echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce]>>C:\test.reg
@echo "batch"="%SDDRIVELETTER%:\\1.bat">>C:\test.reg
@regedit /s C:\test.reg
@shutdown.exe -r -t 10 -f
@:3
@echo all updates are done
@pause
@goto end
@:setup
@echo running openoffice install>>C:\office.txt
@pause
@goto update
@:end

all the other gotos seem to be working except for the one that tells it to goto setup.
@set /P YESNO=do u want to install open office(y/n):
@If /I %YESNO% == 'y' then goto setup

what am i missing?

ghell
05-14-2007, 02:06 AM
Is the syntax of that if correct? Batch uses something like
if condition (
do something
) else (
do something else
)and is pretty strict about which lines those parenthesis are on etc.

I think you are over complicating the whole thing, you can probably cut the whole thing down to very few lines and may be able to completely remove the GOTOs and the labels.

Also, you have completely misused the @s. "echo on" says from now on print all the commands to the console as it runs. @ at the start of a line says "hide this line".
in
@echo on
@do something
@do something else the first line is completely pointless because you are overriding it in every other line. You would have got the same result if you had done either of these:
@do something
@do something else
@echo off
do something
do something elseThe latter is probably what you want. You can debug the code by commenting out the "@echo off" line with ::



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum