VBScript to uninstall older versions of Java on Vista Workstations

S

ShawnTMaloney

I hope this helps someone else...
About a month ago, vulnerabilities were found in in multiple versions
of Java JRE, and Sun released updates. See "US-CERT Technical Cyber
Security Alert TA08-066A -- Sun Updates for Multiple Vulnerabilities
in Java" for more details.
The problem I ran into was that installing the new version left the
old versions, which meant the PC was still vulnerable. If you have one
PC, Programs/Features works fine, but if you're an admin and need to
update 500 PC's, that's just not going to work.
The safe versions of Java are:
JDK and JRE 6 Update 5 or later
JDK and JRE 5.0 Update 15 or later
SDK and JRE 1.4.2_17 or later

Listed below is a VBscript I wrote to remove all the versions on Java
I have installed in my end user environment. It works on Vista, but I
haven't tested it on XP/2000.
You may need to add additional versions for your environment. To add
another version, you'll need to tweak a couple of the variables. Each
section of the code is commented with the version it is removing. For
example, this section removes version 1.4.2_01:

'Uninstall Java 2 Runtime Environment, SE v1.4.2_01
Set colJava4dot1 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_01'")
For Each objSoftware in colJava4dot1
objSoftware.Uninstall()
Next

To add another version:
Copy one section of the remove code, and paste it to a new line.

change "colJava4dot1" to colJava4dot## - where ## is the additional
version you want to remove.
Be sure to change the colJava4dot## in the "Set" and "For Each"
statement.

In the ("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_01'")
'Java 2 Runtime Environment, SE v1.4.2_01' is what you see when you
look in Programs/Features. Make sure it is exactly as it appears
there, and also make sure it is enclosed in single quotes. The end of
the line also has the " and )

You'll also want to change the comment line to reflect the version it
is removing.

You can call the .vbs script from a batch file using: cscript
scriptname.vbs
You'll have to work out how to install the new versions... In my
environment, I use LANDesk, and I have a batch file that calls the
VBscript to remove all the old versions, and then installs the new 4,
5 & 6 versions. The machine doesn't have to reboot inbetween the
uninstall/upgrade.



Here's the script:
Copy all the text below, paste it into notepad and save it with a .vbs
extension.


'Start Script

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Uninstall Java 2 Runtime Environment, SE v1.4.1_02
Set colJava41dot2 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.1_02'")
For Each objSoftware in colJava41dot2
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE v1.4.2_01
Set colJava4dot1 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_01'")
For Each objSoftware in colJava4dot1
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE v1.4.2_02
Set colJava4dot2 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_02'")
For Each objSoftware in colJava4dot2
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE v1.4.2_03
Set colJava4dot3 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_03'")
For Each objSoftware in colJava4dot3
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE v1.4.2_04
Set colJava4dot4 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_04'")
For Each objSoftware in colJava4dot4
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE v1.4.2_05
Set colJava4dot5 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_05'")
For Each objSoftware in colJava4dot5
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE v1.4.2_06
Set colJava4dot6 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_06'")
For Each objSoftware in colJava4dot6
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE v1.4.2_12
Set colJava4dot12 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_12'")
For Each objSoftware in colJava4dot12
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE v1.4.2_15
Set colJava4dot15 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java 2 Runtime
Environment, SE v1.4.2_15'")
For Each objSoftware in colJava4dot15
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 1
Set colJava5dot1 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 1'")
For Each objSoftware in colJava5dot1
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 2
Set colJava5dot2 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 2'")
For Each objSoftware in colJava5dot2
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 3
Set colJava5dot3 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 3'")
For Each objSoftware in colJava5dot3
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 5
Set colJava5dot5 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 5'")
For Each objSoftware in colJava5dot5
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 6
Set colJava5dot6 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 6'")
For Each objSoftware in colJava5dot6
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 9
Set colJava5dot9 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 9'")
For Each objSoftware in colJava5dot9
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 10
Set colJava5dot10 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 10'")
For Each objSoftware in colJava5dot10
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 11
Set colJava5dot11 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 11'")
For Each objSoftware in colJava5dot11
objSoftware.Uninstall()
Next

' Uninstall J2SE Runtime Environment 5.0 Update 12
Set colJava5dot12 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'J2SE Runtime
Environment 5.0 Update 12'")
For Each objSoftware in colJava5dot12
objSoftware.Uninstall()
Next

'Uninstall Java(TM) SE Runtime Environment 6
Set colJava6 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java(TM) SE Runtime
Environment 6'")
For Each objSoftware in colJava6
objSoftware.Uninstall()
Next

'Uninstall Java(TM) SE Runtime Environment 6 Update 1
Set colJava6dot1 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java(TM) SE Runtime
Environment 6 Update 1'")
For Each objSoftware in colJava6dot1
objSoftware.Uninstall()
Next

'Uninstall Java(TM) 6 Update 2
Set colJava6dot2 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java(TM) 6 Update 2'")
For Each objSoftware in colJava6dot2
objSoftware.Uninstall()
Next

'Uninstall Java(TM) 6 Update 3
Set colJava6dot3 = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Java(TM) 6 Update 3'")
For Each objSoftware in colJava6dot3
objSoftware.Uninstall()
Next

'End Script
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top