Java DST update script
- 2
- Add a Comment
- No Related Post
In dealing with the upcoming Daylight Savings Time changes, Java is one of the things that needs to be updated. Sun has released a tool that updates the Java instances installed on a system with the new DST information. The problem is that Java doesn’t ever uninstall itself when it upgrades, and some applications might have embedded Java.
On my system with a Vista Ultimate clean install that’s about a month old, here’s what a search for Java finds:
C:\Users\jtdennis>dir c:\ /s /b | find “\java.exe”
c:\Program Files\Java\jre1.5.0_11\bin\java.exe
c:\Program Files\Java\jre1.6.0\bin\java.exe
c:\Windows\System32\java.exe
That’s for a relatively clean system Since I’m responsible for multiple computers, it’s easy to see how much trouble it can be to install the update on every version of Java installed on Windows installs that are older. I have come up with a couple scripts that will find every copy of Java on a system and run Sun’s updater program against each one. Add it to a login script and the updating is much, much easier. I’m sure the scripts could be combined into a single one, but I have limited VBScripting abilities and not a lot of time available to work on it.
The script needs to be run as an Administrator, and in Vista it needs to run elevated.
Here are the scripts:
dstjava.cmd
@echo off
::if c:\javadst.txt exists, don’t try and upgrade again.
if exist c:\javadst.txt goto javaend
::find all java locations and save to a text file
dir c:\ /s /b | find “\java.exe”>%temp%\java.txt
::run the upgrade with the text file as input
cscript \\server\scriptdir\dstjava.vbs %temp%\java.txt
::save text file to prevent future upgrades.
echo “java updated for DST changes.”>c:\javadst.txt
:javaend
dstjava.vbs:
Set objArgs = WScript.Arguments
Const ForReading = 1
Set objDictionary = CreateObject(”Scripting.Dictionary”)
Set objFSO = CreateObject(”Scripting.FileSystemObject”)
Set objTextFile = objFSO.OpenTextFile(objArgs(0), ForReading)i = 0
Do While objTextFile.AtEndOfStream <> True
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
For Each objItem in objDictionary
strExe = objDictionary.Item(objItem)
Set wshShell = WScript.CreateObject (”WSCript.shell”)
wshShell.run “”"” & strExe & “”"” & ” -jar ” & “\\server\scriptdir\tz\tzupdater.jar” & ” -u”
wshShell.run “”"” & strExe & “”"” & ” -jar ” & “\\server\scriptdir\tz\tzupdater131.jar” & ” -u”
set wshshell = nothing
‘test to make sure executed command is correct
‘Wscript.Echo “”"” & strExe & “”"” & ” -jar ” & “\\server\scriptdir\tz\tzupdater.jar” & ” -u”
Next
[tags]java, dst, daylight savings time, scripts, windows[/tags]

2 Comments
Steve Poirier
March 6th, 2007
at 9:36pm
Here is my version that only uses batch commands. I don’t have a copy of tzupdater131.jar so I cannot verify that part will work.
@ECHO OFF
::Find the location of all copies of java.exe and save to a text file
DIR java.exe /s /b >%temp%\java.txt
::Run the upgrade with the text file as input
FOR /F “delims=” %J IN (%temp%\java.txt) DO @”%J” -jar c:\tzupdater.jar -u
FOR /F “delims=” %J IN (%temp%\java.txt) DO @”%J” -jar c:\tzupdater131.jar -u
::This can do the job without creating a text file but it causes alot of screen output
::FOR /R %SYSTEMDRIVE% %J IN (java.exe) DO @”%J” -jar c:\tzupdater.jar -u
Bill
March 7th, 2007
at 9:31pm
Thanks for the ideas. This can also be done within a single command file to avoid vbscript. Push it via group policy to avoid the Administrator requirement.
____________________________
:: *** JavaDST.cmd ***
@echo off
REM avoid rerunning the script
if exist c:\javadst.flag goto :eof
dir c:\java.exe /s /b > c:\javadst.txt
for /f “tokens=*” %%a in (c:\javadst.txt) do (
set str=%%a
call :run
)
REM set flag to indicate successful completion
ren c:\javadst.txt javadst.flag
goto :eof
:run
%str:~0,2%
CD %str:~0,-9%
java.exe -jar \\yourpathhere\tzupdater.jar -u
goto :eof