Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2004
    Location
    USA
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    batch goto issue

    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.

    Code:
    @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?

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    Is the syntax of that if correct? Batch uses something like
    Code:
    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
    Code:
    @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:
    Code:
    @do something
    @do something else
    Code:
    @echo off
    do something
    do something else
    The latter is probably what you want. You can debug the code by commenting out the "@echo off" line with ::


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •