Improve company productivity with a Business Account.Sign Up


Script needed to Remove all Sun Java

Posted on 2012-03-27
Medium Priority
Last Modified: 2014-07-26
We want to have a script we can deploy from AD to remove all Sun Java versions on a workstation/server.  Here is the caveot, we do not want to remove IBM Java.

I've found loads of scripts out there, but nothing that encorporates what I am looking for.

Has anyone run across something like this?  Anyone help to point me towards an idea of how to do this from the scripts that are already out on the net?

We plan to remove all Sun Java versions and then install the latest version.
Question by:vmToaster
  • 4
  • 3
LVL 47

Expert Comment

ID: 37774878
what is your opertaiong system?
is it windows ?

why do you need to remove all these java's ?

They don't make any differences until you start using  them

Author Comment

ID: 37775002
Windows server and WS.

It is needed to meet a requirement outside our control. I do understand they won't be used, but they present security issues.

LVL 47

Expert Comment

ID: 37775023
Well, you can go to control panel and to add or Remove Programs and
post waht Java items you have there. we'll find which are from Sun aand then you can uninstall them
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 37775054
Right, but that ignores the script part of the question all together. This is large scale.  

We have had the desired results manually removing this, but it will surely not be an effective way for the entire environment.
LVL 47

Expert Comment

ID: 37775059
I don't think you can do it in general way without at least knowing what versions are installed, especially if they are different, installed across long periods of time. Some versions of java have silent uninstall, some do not have, so, I believe,  across different versions it is very difficult to do

Author Comment

ID: 37776403
There are some scripts out there that on tge net that claim to uninstall all versions.  They list most versions, but they are older scripts.

So it is surely possible at least.
LVL 13

Accepted Solution

Daz_1234 earned 2000 total points
ID: 37776754
Hi vmToaster,

Your 'itninja' link (originally there includes a script I wrote (I am the same 'Daz'), adapted from the original poster's sloppy script, that we still use in mostly the same format today.  I have posted below the version we still use live.  It was written for, and tested on, Windows XP (and therefore should be Server 2003 compatible).

In order to filter out any that you do *not* want to uninstall, you need to find something to identify them and ignore them.  The script creates C:\Logs and logs there what it does.  

I can easily help you to tweak it to retain some version depending on what is unique about them.

If you need an x64 version then it looks like other re-written script versions by other contributors are good on that page too, and again they should be able to be modified quite easily.

I think that your first step should be to look in add / remove programs and look at all the versions of Java, both Sun and not Sun.  look at what is unique about the displayname of the IBM versions, or if the versions are unique and do not clash with Sun's.  Any factor can be used to distinguish.

For Sun / Oracle Java, from version 6 update 11, they no longer install alongside the previous version, but instead upgrade it.  But they will leave installed anything earlier than that.


'# D.Collins - 16:02 02/04/2009
'# Uninstalls any and all versions of Java Runtime.
'# Based on a script by 'muaddip' from message boards.

Option Explicit

Dim wshShell, fso, strLogFile, ts, strTempDir, strTempISS, strUnString, tsIn, blFound
Dim strUninstLine, CLSID, search5, search6, search7, strJRE1, strDisplayName, strDisplayVersion
Dim strPublisher, strUninstallString, strJREUninstallString, strJREDisplayName
Dim search1, search2, search3, search4, strJREUninstallStringNEW, ret, strUninstCMD
Dim tsISS, strSetupexe, qVal, strComputername
Dim strTo, strFrom, strSubject, strBody, strAttach, intPriority, iResult

qVal = 0

Set wshShell = CreateObject("WScript.Shell") 
Set fso = CreateObject("Scripting.FileSystemObject") 

strComputername = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

If Not fso.FolderExists("C:\Logs") Then fso.CreateFolder("C:\Logs")
strLogFile = "C:\Logs\Java_Uninstall_" & strComputername & ".log"
Set ts = fso.OpenTextFile(strLogFile, 8, True)

ts.WriteLine String(80, "_") 
ts.WriteLine String(80, "¯") 
ts.WriteLine Now() & " - Java Runtime(s) uninstallation"
ts.WriteLine String(80, "_") & vbCrlf

'# Generate Registry extracts from 'Uninstall' keys.

'# Kill Java Processes

strTempDir = wshShell.ExpandEnvironmentStrings("%temp%")
strTempISS = strTempDir & "\iss" 
strUnString = " -s -a /s /f1" 
Set tsIn = fso.OpenTextFile(strTempDir & "\uninstall.tmp", 1) 

If Not fso.FolderExists(strTempISS) Then fso.CreateFolder(strTempISS) 

blFound = False

Do While Not tsIn.AtEndOfStream
    strUninstLine = tsIn.ReadLine 
    CLSID = Mid(strUninstLine, 73, 38) 
    search5 = Instr(strUninstLine, "JRE 1") 
    search6 = Instr(strUninstLine, "]") 
    If search5 > 0 AND search6 > 0 Then 
        strJRE1 = Replace(Mid(strUninstLine, search5, search6),"]","")   
    End If 

    On Error Resume Next

    strDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayName") 
    strDisplayVersion = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayVersion") 
    strPublisher = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\Publisher") 
    strUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\UninstallString") 

    strJREUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strJRE1 & "\UninstallString") 
    strJREDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strJRE1 & "\DisplayName") 

    On Error Goto 0

    'Search for presence of Java and Sun in DisplayName and Publisher 
    search1 = Instr(1, strDisplayName, "Java", 1) 
    search2 = Instr(1, strPublisher, "Sun", 1) 
    search3 = Instr(1, strDisplayName, "J2SE", 1) 
    search4 = Instr(1, strUninstallString, "setup.exe", 1)
    search7 = InStr(1, strDisplayName, "Development", 1) + InStr(1, strDisplayName, "Java DB", 1)

    If strJREUninstallString <> "" Then
        blFound = True
        '# JRE 1 found
        strJREUninstallStringNEW = Replace(strJREUninstallString," -f"," -s -a /s /f") 
        ts.WriteLine Now() & " - " & strJREDisplayName
        ts.WriteLine Now() & " - Uninstall String sent: " & strJREUninstallStringNEW 
        ret = wshShell.Run(strJREUninstallStringNEW , 0, True)
        ts.WriteLine Now() & " - Return: " & ret
        If ret <> 0 And ret <> 3010 And ret <> 1618 And ret <> 1605 Then qVal = 1
        If ret = 1618 Then qVal = 1618

    ElseIf search7 = 0 And search1 > 0 Or search3 > 0 And search2 > 0 Then
        blFound = True
        strUninstCMD = "msiexec.exe /x " & CLSID & " /norestart /qn"

        If search4 > 0 Then
            '# Old InstallShield setup found
            Set tsISS = fso.OpenTextFile(strTempISS & "\" & CLSID & ".iss", 2, True)
            'Create Response file for any Java Version 
            tsISS.WriteLine "[InstallShield Silent]" 
            tsISS.WriteLine "Version=v6.00.000" 
            tsISS.WriteLine "File=Response File" 
            tsISS.WriteLine "[File Transfer]" 
            tsISS.WriteLine "OverwrittenReadOnly=NoToAll" 
            tsISS.WriteLine "[" & CLSID & "-DlgOrder]" 
            tsISS.WriteLine "Dlg0=" & CLSID & "-SprintfBox-0" 
            tsISS.WriteLine "Count=2" 
            tsISS.WriteLine "Dlg1=" & CLSID & "-File Transfer" 
            tsISS.WriteLine "[" & CLSID & "-SprintfBox-0]" 
            tsISS.WriteLine "Result=1" 
            tsISS.WriteLine "[Application]" 
            tsISS.WriteLine "Name=Java 2 Runtime Environment, SE v1.4.0_01"
            tsISS.WriteLine "Version=1.4.0_01"
            tsISS.WriteLine "Company=JavaSoft"
            tsISS.WriteLine "Lang=0009"
            tsISS.WriteLine "[" & CLSID & "-File Transfer]"
            tsISS.WriteLine "SharedFile=YesToAll"

            strSetupexe = Left(strUninstallString, search4 + 9) 
            strUninstCMD =  strSetupexe & strUnString & Chr(34) & strTempISS & "\" & CLSID & ".iss" & Chr(34) 
        End If

        ts.WriteLine Now() & " - " & strDisplayName & "    - Version: " & strDisplayVersion

    End If 



If Not blFound Then
    ts.WriteLine Now() & " - No Java Runtime versions found installed."
    qVal = 99
End If

ts.WriteLine String(80, "_") 
ts.WriteLine String(80, "¯") 
fso.DeleteFile(strTempDir & "\uninstall.tmp")

If ret <> 0 and ret <> 3010 and ret <> 1618 and qVal <> 99 then
    strSubject  = "[Log JRE_Uninstall_Error] JRE Uninstaller log from " & strComputername
    strSubject  = "[Log JRE_Uninstall] JRE Uninstaller log from " & strComputername
End if


Sub PreFlight()
    '# Creates temp files containing extracts from registry 'Uninstall' keys.
    Dim wshShell, fso, sTemp
    Set wshShell = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    sTemp = wshShell.ExpandEnvironmentStrings("%temp%")
    wshShell.Run "REGEDIT /E %temp%\registry.tmp HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall", 0, True
    wshShell.Run "cmd /c type %temp%\registry.tmp | find /i ""{"" | find /i ""}]"" > %temp%\uninstall.tmp ", 0, True
    wshShell.Run "cmd /c type %temp%\registry.tmp | find /i ""JRE 1"" >> %temp%\uninstall.tmp ", 0, True
    If Not fso.FileExists(sTemp & "\uninstall.tmp") Then
        ts.WriteLine Now() & " - No input - %temp%\uninstall.tmp Reg extract not created."
        'ts.WriteLine String(80, "_") 
        'ts.WriteLine String(80, "¯") 
        ts.WriteLine String(80, "-")
    End If
End Sub

Sub KillProc()
    '# kills jusched.exe and jqs.exe if they are running.  These processes will cause the installer to fail.
    Dim wshShell
    Set wshShell = CreateObject("WScript.Shell")
    wshShell.Run "Taskkill /F /IM jusched.exe /T", 0, True
    wshShell.Run "Taskkill /F /IM jqs.exe /T", 0, True
End Sub

Function fVerCompare(sVer1, sVer2)
    '# Returns: 0 if sVer1 = sVer2, 1 if sVer1 > sVer2, 2 if sVer1 < sVer2
    Dim temp, aVer1, aVer2, itemp, i
    '# Ensure that both have at least 4 elements: Major, Minor, Build, Build-Revision
    itemp = UBound(Split(sVer1, "."))
    If itemp < 3 Then
        For i = 1 to 3 - itemp
            sVer1 = sVer1 & ".0"
    End If
    itemp = UBound(Split(sVer2, "."))
    If itemp < 3 Then
        For i = 1 to 3 - itemp
            sVer2 = sVer2 & ".0"
    End If
    aVer1 = Split(sVer1, ".")
    aVer2 = SPlit(sVer2, ".")

    For i = 0 to 3
        If CInt(aVer1(i)) > CInt(aVer2(i)) Then
            fVerCompare = 1
            Exit Function
        End If
        If CInt(aVer1(i)) < CInt(aVer2(i)) Then
            fVerCompare = 2
            Exit Function
        End If
    fVerCompare = 0
End Function

Open in new window


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this post we will learn different types of Android Layout and some basics of an Android App.
In an Exchange Crossforest migration, the distribution groups can be a very complex operation that would cause loss of time, lots of issues and continued headaches if not solved in a timely manner. I had to do a similar project so I created a sc…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

595 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question