Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Administration > VBScript to uninstall older versions of Java on Vista Workstations

Reply
Thread Tools Display Modes

VBScript to uninstall older versions of Java on Vista Workstations

 
 
ShawnTMaloney@gmail.com
Guest
Posts: n/a

 
      04-07-2008

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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files and replace older versions? Nigel Molesworth Windows Vista General Discussion 2 04-20-2008 04:50 PM
How do I uninstall Java from my Vista PC? Victor Delta Windows Vista General Discussion 3 04-12-2008 11:34 AM
older AoE versions Jourei Windows Vista Games 2 11-18-2007 07:34 AM
how do I uninstall MS java VM? T5 Windows Vista General Discussion 4 05-05-2007 09:22 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59