Uninstalling All versions of Java from Windows Silent
843804Dec 16 2005 — edited Jun 24 2008Hi Everyone,
If there is something somewhere on Sun sites that does this already I appologize, but I have to get all previous version of Java from Sun uninstalled from over 700 hundred PCs and so I have created a set of scripts to uninstall all previous versions.
You would copy 'java-uninstall.bat' and 'java-uninstaller.vbs' to c:\temp (make sure you have one) the script can be modified for another location of your choosing. Then you can execite the batch file or have it scheduled to do that with the NT 'AT' command. It will uninstall anything that shows up in Add/Remove programs with 'Java' in the displayname and 'Sun' as the publisher. This would including removal of SDK amd JRE versions, so keep that in mind.
This could probably be used in the login script, but thats not how I deploy updates, it may be fashioned to work with SMS, I don't know. I have a script that goes through network copying files to c$ shares and scheduling it for later in the night.
Also note this just uninstalls the older versions I have another script that does the reinstalling of the newer version.
Files below:
[java-uninstall.bat]
REM <start>
@echo off
if not exist c:\temp\. mkdir c:\temp
REM Export the Uninstall registry keys
start /wait "" REGEDIT /E c:\temp\registry.tmp HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall
REM Filter only the {} keys that Java might be in
type c:\temp\registry.tmp | find /i "\{" | find /i "}]" > c:\temp\uninstall.tmp
REM Run the Vbscript that uses this file to find Java Sun entries to uninstall
cscript c:\temp\java-uninstaller.vbs
REM <end>
[java-uninstaller.vbs]
'<start>
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2
'Open the exported registry file
Set MyFile = fso.OpenTextFile("c:\temp\uninstall.tmp", ForReading)
Do While mYFile.AtEndOfStream <> True
ReadLineTextFile = MyFile.ReadLine
Uninstall = ReadLineTextFile
CLSID = Mid(Uninstall, 73, 38)
On Error Resume Next
'DisplayName
DisplayName=WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"+CLSID+"\DisplayName")
'Publisher
Publisher=WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"+CLSID+"\Publisher")
'Search for presence of Java and Sun in DisplayName and Publisher
search1 = Instr(1, DisplayName, "Java", 1)
search2 = Instr(1, Publisher, "Sun", 1)
'Execute removal if there is a match
Uninstaller="MsiExec.exe /X"&CLSID+" /QN"
if search1>0 And search2>0 Then Return = WshShell.Run(Uninstaller , 1, TRUE)
Loop
'<end>