Solved

Script needed to Remove all Sun Java

Posted on 2012-03-27
10
347 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
  • 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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
 

Author Comment

by:vmToaster
ID: 37776574
0
 
LVL 12

Accepted Solution

by:
Daz_1234 earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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 …

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now