Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Script needed to Remove all Sun Java

Posted on 2012-03-27
10
Medium Priority
?
358 Views
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.
0
Comment
Question by:vmToaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 
LVL 47

Expert Comment

by:for_yan
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
0
 

Author Comment

by:vmToaster
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.

Thanks!
0
 
LVL 47

Expert Comment

by:for_yan
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:vmToaster
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.
0
 
LVL 47

Expert Comment

by:for_yan
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
0
 

Author Comment

by:vmToaster
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.
0
 
LVL 13

Accepted Solution

by:
Daz_1234 earned 2000 total points
ID: 37776754
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

604 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