Script needed to Remove all Sun Java

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.
vmToasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
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
0
vmToasterAuthor Commented:
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.

Thanks!
0
for_yanCommented:
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
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

vmToasterAuthor Commented:
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.
0
for_yanCommented:
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
0
vmToasterAuthor Commented:
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.
0
Daz_1234Commented:
Hi vmToaster,

Your 'itninja' link (originally appdeploy.com) 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.

Daz.

'# D.Collins - 16:02 02/04/2009
'# Uninstalls any and all versions of Java Runtime.
'# Based on a script by 'muaddip' from Appdeploy.com message boards.
'# http://www.appdeploy.com/messageboards/tm.asp?m=29809


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.
PreFlight()

'# Kill Java Processes
KillProc()

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"
            tsISS.Close

            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 

Loop

tsIn.Close

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, "¯") 
ts.Close
fso.DeleteFolder(strTempISS)
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
Else
    strSubject  = "[Log JRE_Uninstall] JRE Uninstaller log from " & strComputername
End if


WScript.Quit(qVal)


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, "-")
        ts.Close
        WScript.Quit(1)
    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"
        Next
    End If
    itemp = UBound(Split(sVer2, "."))
    If itemp < 3 Then
        For i = 1 to 3 - itemp
            sVer2 = sVer2 & ".0"
        Next
    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
    Next
    fVerCompare = 0
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.