I've been using this batch file for a while to remotely update Java on some computers. However, for some reason it just started breaking, and I'm not sure why. Whenever I make the menu selection and then hit 'enter' to confirm and start the patch process, I get the error "goto was unexpected at this time." I can't find anything wrong with the GOTO statement; it's the same as in many of my other batch files.
This happens on Vista SP2 and XP SP3 computers.
Here's the error, and below is the full script.
This is the script, the offending lines are highlighted.
I was previously posting under "GeneralDzur" but hgate73 is my new username.
This happens on Vista SP2 and XP SP3 computers.
Here's the error, and below is the full script.
Okay, ready to attempt mass installation.
Target: All
New Java: jre-6u20-windows-i586-s.exe
Options: /quiet /promptrestart
Names File: java.txt
PSEXEC: 4 second connection timeout
Ready?? Press [enter] to go, or "return" to go back to the menu
Confirm?:
goto was unexpected at this time.
This is the script, the offending lines are highlighted.
Code:
:: Author: [removed]
:: Purpose: Nukes then updates Java to the latest version
:: Requirements: 1. Run this script with a network admin account
:: 2. psexec.exe (from Microsoft) is required, and may be in any of these locations on your local computer:
:: a) the directory you run this script from
:: b) c:\windows\system32\ (preferred)
:: c) in the PATH variable
:: 3. Put the names of your computers, one per line, in the "names" file in the same directory as this script
:: Prep our variables
@echo off
title Mass Java Updater
set VERSION=1.2
set NAMES_FILE=java.txt
set TIMEOUT=4
set TARGET=
:: SET THE JAVA VERSION YOU WANT TO INSTALL HERE
set NEW_JAVA=jre-6u20-windows-i586-s.exe
set OPTION1=/quiet
set OPTION2=/promptrestart
set OPTION3=
set OPTION4=
set OPTION5=
:: Welcome screen
:start
set TARGET=
title Mass Java Updater - %NEW_JAVA% %OPTION1% %OPTION2% %OPTION3% %OPTION4% %OPTION5%
color 07
cls
echo.
echo Mass Java Updater v%VERSION%
echo Requires psexec.exe
echo.
echo - Enter IP or name of a remote computer to update Java on.
echo - Enter "all" to attempt a mass-installation for all computers
echo listed in %NAMES_FILE%. This doesn't always work very well...
:info
echo.
echo Target: %TARGET%
echo New Java: %NEW_JAVA%
echo Options: %OPTION1% %OPTION2% %OPTION3% %OPTION4% %OPTION5%
echo Names File: %NAMES_FILE%
echo PSEXEC: %TIMEOUT% second connection timeout
echo.
:loop
echo.
set /P TARGET= Target computer or "all":
if %TARGET%==exit goto end
if %TARGET%==all goto auto
if %TARGET%==info goto info
goto ready
:ready
cls
echo.
echo Okay, ready to attempt installation using the following settings:
echo.
echo Target: %TARGET%
echo New Java: %NEW_JAVA%
echo Options: %OPTION1% %OPTION2% %OPTION3% %OPTION4% %OPTION5%
echo Names File: %NAMES_FILE%
echo PSEXEC: %TIMEOUT% second connection timeout
echo.
echo Press [enter] to confirm, or "return" to go back to the menu
echo.
set CHOICE=go
set /P CHOICE= Confirm?:
if %CHOICE%==exit goto end
if %CHOICE%==return goto start
if %CHOICE%==go goto execute
:execute
echo.
echo **Step 1** Copying javakiller payload to %TARGET%...
copy javakiller.vbs \\%TARGET%\C$\javakiller.vbs
echo.
echo **Step 2** Executing javakiller payload on %TARGET%. Mu ha ha!
echo.
echo This can take up to 3 minutes.
psexec \\%TARGET% cscript %SystemDrive%\javakiller.vbs //B
del \\%TARGET%\C$\javakiller.vbs
echo.
echo **Step 4** Installing %NEW_JAVA% on %TARGET%...
psexec -n %TIMEOUT% \\%TARGET% -c %NEW_JAVA% %OPTION1% %OPTION2% %OPTION3% %OPTION4% %OPTION5%
echo.
echo **STEP 5** RESULTS (You can ignore any "error code 0" messages)
psexec \\%TARGET% "%ProgramFiles%\Java\jre6\bin\java.exe" -version
echo.
echo Done at %TIME%. Returning to menu...
echo.
title Mass Java Updater
set TARGET=
goto loop
:: HIROSHIMA! this is the "mass" version
:auto
set TARGET=all
set CHOICE=
cls
echo.
echo Okay, ready to attempt mass installation.
echo.
echo Target: All
echo New Java: %NEW_JAVA%
echo Options: %OPTION1% %OPTION2% %OPTION3% %OPTION4% %OPTION5%
echo Names File: %NAMES_FILE%
echo PSEXEC: %TIMEOUT% second connection timeout
echo.
echo Ready?? Press [enter] to go, or "return" to go back to the menu
echo.
set /P CHOICE= Confirm?:
[b][highlight][COLOR=blue] --- REM Script breaks here --- [/color][/highlight][/b]
if %CHOICE%==exit goto end
if %CHOICE%==return goto start
if %CHOICE%=='' goto auto_execute
:auto_execute
echo Alright! Commencing now...
echo.
:: LEGEND:
:: -d Don't wait for the process to terminate (non-interactive), "gun and run"
:: -belownormal Runs the process with the "low" priority.
:: \\* Would run the command for all domain computers for which we have access
:: -n 7 Timeout for connection - wait 7 seconds before moving on
:: -c Copy the specified program to the remote system for execution
:: -f Force the copy even if the remote program already exists
echo **Step 1** Copying the javakiller payload to targets, please wait...
echo.
for /F %%i in (%NAMES_FILE%) do echo %%i && copy /Y javakiller.vbs \\%%i\C$\javakiller.vbs
echo.
echo **Step 2** Executing the javakiller payload on targets.
echo This can take up to 2 minutes.
echo.
:: we do a ping first to create an ARP entry and lower the chance of a connection timeout
for /F %%i in (%NAMES_FILE%) do ping %%i -n 1 >NUL && psexec -n %TIMEOUT% -d \\%%i cscript C:\javakiller.vbs //B
echo.
echo Waiting for javakiller to finish running on remote hosts, recommend
echo waiting at least 4 minutes here before continuing.
pause
echo.
echo **Step 3** Installing %NEW_JAVA% on targets, please wait...
echo.
psexec -n %TIMEOUT% -d @%NAMES_FILE% -c %NEW_JAVA% %OPTION1% %OPTION2% %OPTION3% %OPTION4% %OPTION5%
echo.
echo Java Updater - Complete @ %TIME%
echo.
goto loop
:end
title %USERNAME%
I was previously posting under "GeneralDzur" but hgate73 is my new username.