/build/static/layout/Breadcrumb_cap_w.png

Silent Uninstall Java All Versions

A wrote 2 files for uninstallin All Java

---- 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
type c:\temp\registry.tmp | find /i "JRE 1" >> c:\temp\uninstall.tmp

REM Run the Vbscript that uses this file to find Java Sun entries to uninstall
cscript "java-uninstaller.vbs"
REM <end>


---- java-uninstall.bat -----

---- java-uninstaller.vbs -----

On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2
TempDir = "c:\temp"
TempISS = "c:\temp\iss"
LogFile = "uninst.log"
UnString = " -s -a /s /f1"
Set MyFile = fso.OpenTextFile(TempDir & "\uninstall.tmp", ForReading)
Set ts = fso.CreateTextFile(LogFile)
Set f = fso.CreateFolder(TempISS)

Do While MyFile.AtEndOfStream <> True
ReadLineTextFile = MyFile.ReadLine
Uninstall = ReadLineTextFile
CLSID = Mid(Uninstall, 73, 38)
search5 = Instr(Uninstall, "JRE 1")
search6 = Instr(Uninstall, "]")
If search5 > 0 AND search6 > 0 Then
JRE1 = Replace(Mid(Uninstall, search5, search6),"]","")
End If

'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")

'UninstallString
UninstallString=WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\UninstallString")

'JREUninstallString
JREUninstallString=WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & JRE1 & "\UninstallString")

If JREUninstallString <> "" Then
JREUN = Replace(JREUninstallString," -f"," -s -a /s /f")
ts.writeline JREUN
Return = WshShell.Run(JREUN , 1, TRUE)
End If


'Search for presence of Java and Sun in DisplayName and Publisher
search1 = Instr(1, DisplayName, "Java", 1)
search2 = Instr(1, Publisher, "Sun", 1)
search3 = Instr(1, DisplayName, "J2SE", 1)
search4 = Instr(1, UninstallString, "setup.exe", 1)
'Execute removal if there is a match
Uninstaller="MsiExec.exe /X"&CLSID+" /QN"
if search1 > 0 or search3 > 0 and search2 > 0 Then
ts.writeline Uninstaller

Set iss = fso.CreateTextFile(TempISS & "\" & CLSID & ".iss")

'Create Response file for any Java Version
iss.writeline "[InstallShield Silent]"
iss.writeline "Version=v6.00.000"
iss.writeline "File=Response File"
iss.writeline "[File Transfer]"
iss.writeline "OverwrittenReadOnly=NoToAll"
iss.writeline "[" & CLSID & "-DlgOrder]"
iss.writeline "Dlg0=" & CLSID & "-SprintfBox-0"
iss.writeline "Count=2"
iss.writeline "Dlg1=" & CLSID & "-File Transfer"
iss.writeline "[" & CLSID & "-SprintfBox-0]"
iss.writeline "Result=1"
iss.writeline "[Application]"
iss.writeline "Name=Java 2 Runtime Environment, SE v1.4.0_01"
iss.writeline "Version=1.4.0_01"
iss.writeline "Company=JavaSoft"
iss.writeline "Lang=0009"
iss.writeline "[" & CLSID & "-File Transfer]"
iss.writeline "SharedFile=YesToAll"

If search4 > 0 Then
ss = Left(UninstallString,search4 + 9)
setupuninstal = ss & UnString & Chr(34) & TempISS & "\" & CLSID & ".iss" & Chr(34)
ts.writeline setupuninstal
Return = WshShell.Run(setupuninstal , 1, TRUE)
End If
Return = WshShell.Run(Uninstaller , 1, TRUE)
End If
Loop
MyFile.Close
fso.DeleteFolder(TempDir)


---- java-uninstaller.vbs -----

But it run only localy on the system


1 Comment   [ + ] Show comment
  • This is great. I'll put this to use one day. Thanks for the information. - ahunn 8 years ago

Answers (69)

Posted by: dimitridelanghe 11 years ago
White Belt
3

This is nice scripting, but i found it way to many lines, for what is worth it.

I know that WMI has nice features, so i went to search a script for uninstall all our old Java version (this peace of software realy sucks didn't it?)

So here my small script :

 @ECHOOFF
cls
TITLE Uninstalling Java 6... (x86 and x64 versions)

wmic product where "name like 'Java(TM) 6%%'" call uninstall /nointeractive
goto END

:END
pause
exit

And its magic, but it works !

Tested it on XP / Vista / W7 in some cases there was even a JRE7 version installed yet.

So i think many people will love this :D

 

hf + leave some remarks


Comments:
Posted by: dimitridelanghe 11 years ago
White Belt
2

this is cool, but i thought it was way to many scripting, i did know that wmi has superb lines.

I tested some and look at this : 

  @ECHOOFF
cls
TITLE Uninstalling Java 6... (x86 and x64 versions)

wmic product where "name like 'Java(TM) 6%%'" call uninstall /nointeractive
goto END

:END
pause
exit
I have tested in XP / vista / W7 and it all works ! 
Posted by: LabDeploy 12 years ago
Senior Yellow Belt
2
Well, I meant to post this sooner but between work and getting sick it got delayed. Version 3.0 of the script can keep OR remove only specific versions of Java! It also runs on command line parameters now! This one hasn't been as extensively tested as the other scripts since I'm not using it in production. As always with a script on the Internet use with caution and at your own risk!


'***************************************************************************************
'Java removal script.
'Version: 3.0
'Description: Removes specified Java versions based on command line parameters.
' !!!!!!USE AT YOUR OWN RISK!!!!!!!
'2011.03.09 - 2.0 - First version. Assumes %SYSTEMDRIVE%\Logs exists.
'2011.03.23 - 2.1 - Fixes issue running in 32bit SCCM under 64bit Windows.
'2011.03.30 - 2.2 - Adds array of versions to keep.
'2011.04.24 - 3.0 - Added command line parameters. Still doesn't make the log directory!
'***************************************************************************************
'-----------------------------Begin Main Script--------------------------------
Option Explicit

'If help is specified on the command line, show it and quit.
If WScript.Arguments.Named.Count < 1 Or WScript.Arguments.Named.Exists("help") Or WScript.Arguments.Named.Exists("?") Then
PrintHelp()
WScript.Quit(0)
End If

Dim aryVersions, aryVersionsx86Onx64
Dim bolKeepJava
Dim colNamedArguments, colProcesses
Dim objWMIService, objProcessor, objProcess
Dim strArgument, strLogFilePath

'Set default command line parameters.
'The script defaults to removing all versions of Java without leaving uninstall logs.
bolKeepJava = 1
strLogFilePath = ""
aryVersions = Array()
aryVersionsx86Onx64 = Array()

'Start script logging.
WScript.Echo "**********************************"
WScript.Echo "Java uninstall script started at " & Now()

'Parse command line parameters.
If WScript.Arguments.Named.Count > 0 Then
Set colNamedArguments = WScript.Arguments.Named

For Each strArgument in colNamedArguments
Select Case LCase(strArgument)
Case "keeponly"
Case "removeonly"
bolKeepJava = 0
Case "logfilepath"
strLogFilePath = colNamedArguments.Item(strArgument)
Case "versions"
aryVersions = Split(colNamedArguments.Item(strArgument), ";", -1, 1)
Case "versionsx86onx64"
aryVersionsx86Onx64 = Split(colNamedArguments.Item(strArgument), ";", -1, 1)
Case Else
WScript.Echo vbCrLf & "Unknown switch: " & strArgument & "."
WScript.Echo vbCrLf & "Java uninstall script finished at " & Now()
WScript.Echo "**********************************" & vbCrLf
PrintHelp()
WScript.Quit(2)
End Select
Next
End If

'Output the parameters the script was run with.
WScript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Script parameters:"
If bolKeepJava Then
WScript.Echo "Specified Java versions found will be kept. Other versions will be removed."
Else
WScript.Echo "Specified Java versions found will be removed. Other versions will be kept."
End If

'This check is important. It will default the versions array if no versions were specified. Without this the whole thing falls apart.
If (Ubound(aryVersions) < 0 ) Then
aryVersions = Array("FooBar")
WScript.Echo "No native Java versions specified on the command line."
Else
WScript.Echo "Native Java versions specified on the command line."
End If

'If no non-native versions are specified set the non-native array to the native array.
If (Ubound(aryVersionsx86Onx64) < 0) Then
aryVersionsx86Onx64 = aryVersions
WScript.Echo "No x86 Java versions for x64 systems specified on the command line." & vbCrLf & "Using specified native verions for x86 also."
Else
WScript.Echo "x86 Java versions for x64 systems specified on the command line."
End If

If strLogFilePath = "" Or IsNull(strLogFilePath) Then
WScript.Echo "Uninstall logfile path is empty. Uninstall logs will not be created."
Else
'If the log file path does not end in a \ put one on there!
If (StrComp(Right(strLogFilePath,1), "\") <> 0) Then
strLogFilePath = strLogFilePath & "\"
End If
WScript.Echo "Uninstall log file path: " & strLogFilePath & "."
End If
WScript.Echo "----------------------------------"

'Get a WMI Service object.
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (Debug)}\\.\root\cimv2")

'Get processor object. objProcessor.AddressWidth will give us bitness. Check objProcessor.AddressWidth = "32" or "64"
Set objProcessor = GetObject("winmgmts:\\.\root\cimv2:Win32_Processor='cpu0'")

'Kill processes that might prevent installs or uninstalls.
Set colProcesses = objWMIService.ExecQuery("Select Name from Win32_Process Where Name = 'jqs.exe' OR Name = 'jusched.exe' OR Name = 'jucheck.exe' OR Name = 'jp2launcher.exe' OR Name = 'java.exe' OR Name = 'javaws.exe' OR Name = 'javaw.exe'", "WQL", 48)

WScript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Checking for problematic processes."

'Set this to look for errors that aren't fatal when killing processes.
On Error Resume Next

'Cycle through found problematic processes and kill them.
For Each objProcess in colProcesses

WScript.Echo "Found process " & objProcess.Name & "."

objProcess.Terminate()

Select Case Err.Number
Case 0
WScript.Echo "Killed process " & objProcess.Name & "."
Err.Clear
Case -2147217406
WScript.Echo "Process " & objProcess.Name & " already closed."
Err.Clear
Case Else
WScript.Echo "Could not kill process " & objProcess.Name & "! Aborting Script!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
WScript.Echo "Finished problematic process check."
WScript.Echo "----------------------------------"
WScript.Echo vbCrLf & "Java uninstall script finished at " & Now()
WScript.Echo "**********************************" & vbCrLf
WScript.Quit(1)
End Select

Next

'Resume normal error handling.
On Error Goto 0

WScript.Echo "Finished problematic process check."
WScript.Echo "----------------------------------"

'This call will remove x64 versions on a x64 system and x86 versions on a x86 system.
RemoveJava "Software\Microsoft\Windows\CurrentVersion\Uninstall\", aryVersions, strLogFilePath, objProcessor

'This call will remove x86 versions on a x64 system.
If (objProcessor.AddressWidth = "64") Then
RemoveJava "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", aryVersionsx86Onx64, strLogFilePath, objProcessor
End If

WScript.Echo vbCrLf & "Java uninstall script finished at " & Now()
WScript.Echo "**********************************" & vbCrLf
'-------------------------------End Main Script--------------------------------

'---------------------------------Functions------------------------------------
Function RemoveJava(strRegistryPath, aryVersions, strLogFilePath, objProcessor)

Dim objWSHShell, objRegistry, objWbemContext, objSWbemLocator, objSWbemServices
Dim aryUninstallKeys
Dim strUninstallKey, strDisplayName, strUninstallString, strVersion
Dim intUninstallReturnCode

Set objWSHShell = CreateObject("WScript.Shell")

'The following SWbem setup allows a script running in a x86 context, such as under the SCCM client, on a x64 system
'to access the full x64 registry. Without this the actual registry paths will be transparently redirected to the
'Wow6432Node branch for every registry call to HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall.
'Essentially this transparent redirection would hide 64bit Java runtimes from a script running in 32bit mode on a 64bit OS.

'Provides the bitness context parameters for registry calls.
Set objWbemContext = CreateObject("WbemScripting.SWbemNamedValueSet")
objWbemContext.Add "__ProviderArchitecture", objProcessor.AddressWidth
objWbemContext.Add "__RequiredArchitecture", true

'Create SWbemLocator to connect to WMI
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

'Actually connect to the WMI service using the SWbemLocator and the SWbemContext parameters.
Set objSWbemServices = objSWbemLocator.ConnectServer(".","root\default","","",,,,objWbemContext)

'Get the Standard Registry Provider from WMI... finally.
Set objRegistry = objSWbemServices.Get("StdRegProv")

'Find the Java uninstallers hiding in the uninstall key. &H80000002 = HKEY_LOCAL_MACHINE for this function call.
objRegistry.EnumKey &H80000002, strRegistryPath, aryUninstallKeys

'Enable VBS' poor excuse for error handling...
On Error Resume Next

For Each strUninstallKey In aryUninstallKeys

'These must be reset in case the GetStringValue fails to return a value. This way we don't keep values for other pieces of software.
strDisplayName = ""
strUninstallString = ""
intUninstallReturnCode = ""

'DisplayName should always be a REG_SZ
objRegistry.GetStringValue &H80000002, strRegistryPath & strUninstallKey, "DisplayName", strDisplayName

'Just in case GetStringValue doesn't retrieve what we want.
If Err.Number <> 0 Then
Wscript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Could not retrieve DisplayName at " & strRegistryPath & strUninstallKey & "!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Wscript.Echo "----------------------------------"
strDisplayName = ""
Err.Clear
End If

'In English: If the DisplayName contains either Java OR the DisplayName contains J2SE Runtime Environment
'AND if the DisplayName does not contain Development AND if the DisplayName does not contain JavaDB
'AND if the DisplayName does not contain Web Start
'AND if the DisplayName does not contain SAS
'AND if the DisplayName does not contain Java Auto Update then do the if block.
'Fun, eh?
'You could remove the Web Start line to get rid of JWS but the uninstall string If block would have to account for that. It currently doesn't.

If ((Instr(1, strDisplayName, "Java", 1) OR (Instr(1, strDisplayName, "J2SE Runtime Environment", 1))) _
AND ((Instr(1, strDisplayName, "Development", 1) + Instr(1, strDisplayName, "JavaDB", 1)) < 1) _
AND (Instr(1, strDisplayName, "Web Start", 1) < 1) _
AND (Instr(1, strDisplayName, "SAS", 1) < 1) _
AND (Instr(1, strDisplayName, "Java Auto Update", 1) < 1)) Then

Wscript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Found version: " & strDisplayName
WScript.Echo "Found at: HKEY_LOCAL_MACHINE\" & strRegistryPath & strUninstallKey

'UninstallString might be a REG_EXPAND_SZ but GetStringValue should retrieve what we want.
objRegistry.GetStringValue &H80000002, strRegistryPath & strUninstallKey, "UninstallString", strUninstallString

'Just in case GetStringValue doesn't retrieve what we want.
If Err.Number <> 0 Then
Wscript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Could not retrieve uninstall information for " & strDisplayName & "!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Wscript.Echo "----------------------------------"
strUninstallString = ""
Err.Clear
End If

'Slightly convoluted logic that determines if we're keeping or removing specific versions.
For Each strVersion In aryVersions
If (bolKeepJava) Then
If (Instr(1, strDisplayName, strVersion, 1) > 0) Then
strUninstallString = ""
End If
Else
If (Instr(1, strDisplayName, strVersion, 1) < 1) Then
strUninstallString = ""
End If
End If
Next

If (strUninstallString <> "") Then
'Look for very old JRE 1.1, 1.2.x, or 1.3.0 to 1.3.0_04 and 1.3.1 to 1.3.1_04 InstallShield installs.
If (Instr(1, strUninstallKey, "JRE 1", 1)) Then
strUninstallString = Replace(strUninstallString, "-f", "-a -x -y -f")
'Look for 1.3.0_05 and 1.3.1_05 to 1.3.1_20 InstallShield based installs.
ElseIf (Instr(1, strUninstallString, "-uninst", 1)) Then
strUninstallString = ""
WScript.Echo "Java versions 1.3.0_05 and 1.3.1_05 through 1.3.1_20 cannot be silently uninstalled."
'Look for a 1.4.0 to 1.4.1_07 InstallShield installation.
ElseIf (Instr(1, strUninstallString, "Anytext", 1)) Then
'Create ISS script for this install and fix the uninstall string.
If (CreateISSFile(strUninstallKey, objWSHShell.ExpandEnvironmentStrings("%TEMP%"))) Then
strUninstallString = Replace(strUninstallString, "Anytext", "/s /SMS /w /f1""" & objWSHShell.ExpandEnvironmentStrings("%TEMP%") _
& "\" & strUninstallKey & ".iss""")
'Check and add the logfile to the uninstaller string.
If (strLogFilePath <> "") Then
strUninstallString = strUninstallString & " /f2""" & strLogFilePath & strDisplayName & "_Uninstall.txt"""
End If
Else
strUninstallString = ""
End If
'Look for 1.4.2 and up MSI based InstallShield installs.
ElseIf (Instr(1, strUninstallString, "msiexec.exe", 1)) Then
'Create MSIEXEC uninstall string.
strUninstallString = "MSIEXEC.EXE /X " & strUninstallKey & " /qn /norestart"
'Check and add the logfile to the uninstaller string.
If (strLogFilePath <> "") Then
strUninstallString = strUninstallString & " /l*v """ & strLogFilePath & strDisplayName & "_Uninstall.txt"""
End If
Else
strUninstallString = ""
End If
Else
strUninstallString = ""
End If

WScript.Echo "Uninstall string: " & strUninstallString

If (strUninstallString = "") Then
WScript.Echo strDisplayName & " was not uninstalled."
Else
'Run the uninstaller.
intUninstallReturnCode = objWSHShell.Run(strUninstallString, 0, true)
WScript.Echo "Uninstall return code was: " & intUninstallReturnCode & "."
End If

WScript.Echo "----------------------------------"

End If

Next

'Resume normal quit on error behavior.
On Error GoTo 0

End Function

Function CreateISSFile(strUninstallKey, strTempPath)
On Error Resume Next

Dim objFileSystem, objUninstallScript

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Create InstallShield ISS script file for the uninstallation.
Set objUninstallScript = objFileSystem.OpenTextFile(strTempPath & "\" & strUninstallKey & ".iss", 2, True)

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If

'One ugly write statement to cut down on the ammount of error checking that has to be done.
'That SharedFile=YesToAll creates problems with multiple versions of 1.4.0 to 1.4.1_07 installed.
objUninstallScript.Write "[InstallShield Silent]" & vbCrLf & "Version=v6.00.000" & vbCrLf & "File=Response File" & vbCrLf & "[File Transfer]" & _
vbCrLf & "OverwrittenReadOnly=NoToAll" & vbCrLf & "[" & strUninstallKey & "-DlgOrder]" & vbCrLf & "Dlg0=" & strUninstallKey & "-SprintfBox-0" & _
vbCrLf & "Count=2" & vbCrLf & "Dlg1=" & strUninstallKey & "-File Transfer" & vbCrLf & "[" & strUninstallKey & "-SprintfBox-0]" & vbCrLf & "Result=1" & _
vbCrLf & "[Application]" & vbCrLf & "Name=Java 2 Runtime Environment, SE v1.4.0" & vbCrLf & "Version=1.4.0" & vbCrLf & "Company=JavaSoft" & _
vbCrLf & "Lang=0009" & vbCrLf & "[" & strUninstallKey & "-File Transfer]" & vbCrLf & "SharedFile=NoToAll"

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If

objUninstallScript.Close

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If


CreateISSFile = 1

End Function

Function PrintHelp()
'Just prints out the help when run with /help /? or no arguments.
WScript.Echo vbCrLf & "Java Runtime Environment Removal Script v3.0" & vbCrLf
WScript.Echo "Removes Java runtimes based on command line parameters." & vbCrLf & "Default parameters removes all Java versions without creating logs."
WScript.Echo "Does not uninstall Java versions 1.3.0_05 and 1.3.1_05 through 1.3.1_20." & vbCrLf & "They do not uninstall silently." & vbCrLf
WScript.Echo "Command line switches:" & vbCrLf
WScript.Echo "/keeponly" & vbTab & vbTab & "Script keeps only versions specified." & vbCrLf & vbTab & vbTab & vbTab & "If no versions are specified no versions are kept." & vbCrLf
WScript.Echo "/removeonly" & vbTab & vbTab & "Script removes only versions specified." & vbCrLf & vbTab & vbTab & vbTab & "If no versions are specified no versions are removed." & vbCrLf
WScript.Echo "/versions:" & vbTab & vbTab & "Specifies verions to act on." & vbCrLf & vbTab & vbTab & vbTab & "Versions are seperated by semicolons." & vbCrLf & vbTab & vbTab & vbTab & _
"By default specified versions are kept." & vbCrLf & vbTab & vbTab & vbTab & "MUST MATCH THE DISPLAY NAME IN ADD/REMOVE PROGRAMS" & vbCrLf
WScript.Echo "/versionsx86onx64:" & vbTab & "Specifies x86 runtime versions to keep on a x64 system." & vbCrLf & vbTab & vbTab & vbTab & _
"Versions are seperated by semicolon." & vbCrLf & vbTab & vbTab & vbTab & _
"If no x86 versions are specified script uses versions" & vbCrLf & vbTab & vbTab & vbTab & "specified by /versions for both x64 and x86 runtimes." _
& vbCrLf & vbTab & vbTab & vbTab & "MUST MATCH THE DISPLAY NAME IN ADD/REMOVE PROGRAMS" & vbCrLf
Wscript.Echo "/logfilepath:" & vbTab & vbTab & "Sets path for uninstall log file from Java runtimes." & vbCrLf & vbTab & vbTab & vbTab & _
"If path does not exist uninstallers will fail." & vbCrLf
WScript.Echo "Examples:" & vbCrLf
WScript.Echo "cscript /nologo JavaUninstallScript.vbs /keeponly /versions:""Java(TM) 6 Update 24;J2SE Runtime Environment 5.0 Update 16"" /logfilepath:""C:\Temp"""
WScript.Echo "Removes all Java Runtimes found except Java 6 Update 24 and J2SE 5 Update 16 and places the uninstall logs in C:\Temp." & vbCrLf
WScript.Echo "cscript /nologo JavaUninstallScript.vbs /keeponly /versions:""Java(TM) 6 Update 24"" /versionsx86onx64:""J2SE Runtime Environment 5.0 Update 16"" /logfilepath:""C:\Temp"""
WScript.Echo "Removes all Java Runtimes found except x64 Java 6 Update 24 and x86 J2SE 5 Update 16 on a x64 system and places the uninstall logs in C:\Temp." & vbCrLf
WScript.Echo "cscript /nologo JavaUninstallScript.vbs /keeponly"
WScript.Echo "Removes all Java Runtimes without creating logs." & vbCrLf
WScript.Echo "cscript /nologo JavaUninstallScript.vbs /removeonly"
WScript.Echo "Keeps all Java Runtimes. Only useful for making a list of installed runtimes." & vbCrLf
End Function
Posted by: Oranif 4 years ago
White Belt
1

This post has been made 12 years ago. AND IT STILL WORK 12 YEARS AFTER! Thanks a lot for your tip!


Posted by: ComputerX 15 years ago
Yellow Belt
1
ORIGINAL: VBScab

[sigh...] ...the script - while undoubtedly pretty and effective - is, like so many I see, almost completely without error-trapping.



Then modify it to include error handling. [;)]

I don't code at all; I was impressed that I could generally follow what was happening.

My coworker added the ability to exclude a version of the JRE. He isn't a VBS person, but it seems to work. Here is his version.


'# Galen Dobbs - 12:42 19/03/2009
'# Uninstalls all but the chosen version of Java Runtime.
'# Based on a script by 'Daz' from the Appdeploy.com message boards.
'# Based on a script by 'muaddip' from the Appdeploy.com message boards.
'# http://itninja.com/question/stopping-a-service09


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, strCurrentVersion, searchCurVer

'Change this to match the version that you don't want to have it uninstall
strCurrentVersion = "Java(TM) 6 Update 12"

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)

'Make sure it is not the current version
searchCurVer = InStr(1, strDisplayName, strCurrentVersion, 1)

If searchCurVer > 0 Then
ts.WriteLine Now() & " - Current Version: " & strDisplayName & " found, leaving it alone."

ElseIf 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 Then qVal = 1

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
ts.WriteLine Now() & " - Uninstall String sent: " & strUninstCMD
ret = wshShell.Run(strUninstCMD , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
End If

Loop

tsIn.Close

If Not blFound Then
ts.WriteLine Now() & " - No Old 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")

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.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



Dan

Comments:
  • Are you guys doing something to make this look formatted? That is gibberish! Is there no code tag here? test - rich-weber 11 years ago
Posted by: Daz 15 years ago
Orange Belt
1
Dan,

You're addition is pretty much what I would have advised anyway. Thanks.

VBScab,

I appreciate the comments about error trapping.

Error-Trapping is immensely time consuming. Therefore I tailor the error-trapping I do to the risk / likelyhood / probability of the errors occurring. I used Altiris NS to push out the script. The calling script copied the logs back to a central location, and I could see from NS if the process was attempted. Therefore:
1: If the script failed catastrophically before logging anything, I would see the script fail from NS.
2: If any other part of the script failed, I would see from NS that the computer does not have all Java versions removed and I would see from the Log exactly what happened up to that point.
3: I use this script on Windows XP SP2 and SP3 computers only. If any of those computers fail to create the only two objects I use here (WScript.Shell and Scripting.FileSystemObject) the computer would have far more problems than running my script.
4: I have run it on 216 computers so far remotely (extended pilot) and the script has not failed yet (no excuse though).
5: If I did not have the time constraints I had, I would not have shelled out at all in the Pre-Flight sub. I would have retrieved the registry settings directly using the stdRegProv. I only shelled out in this sub to retain the same format used by muaddip in his original effort. Having said that, I completely accept your point about checking the variable contains data, under normal circumstances.
6: I also take the point about killing the process / checking it's dead. But if the msiexec process fails to uninstall one of the versions because the process is still running, the msiexec return code will be logged in the log.

SO ... I agree completely with your critique, however I believe that the effort you put into error-trapping has to be proportionate to the chances of an error occurring undetected. In my case (and I only wrote the script for my situation, sharing was a courtesy), it was virtually impossible for the script to fail and me not know about it.

Many thanks,
Daz.
Posted by: ComputerX 15 years ago
Yellow Belt
1
Here is our latest version.

'# Galen Dobbs - 13:20 23/03/2009
'# Uninstalls all but the chosen version of Java Runtime.
'# If the current version is not installed, it installs it from the specified path.
'# Based on a script by 'Daz' from Appdeploy.com message boards.
'# http://itninja.com/question/stopping-a-service09


Option Explicit

Dim wshShell, fso, strLogFile, ts, strTempDir, strTempISS, strUnString, tsIn
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, strCurrentVersion, strInstallMST
Dim searchCurVer, CurVerFound, strArrayCount, strLogPath, strInstallCMD, strInstallMSI, strInstallLog

Dim arrayJREDisplayName()
Dim arrayJREUninstallString()

'# Change this to match the version that you don't want to have it uninstall
strCurrentVersion = "Java(TM) 6 Update 13"

'# Set these to the desired log path and current version installer location
strLogPath = "[LogPath]"
strInstallMSI = "[ServerPath]\JRE1.6.0_13\jre1.6.0_13.msi"
strInstallMST = "[ServerPath]\JRE1.6.0_13\jre1.6.0_13.mst"

qVal = 0
strArrayCount = 0
ReDim arrayJREDisplayName(strArrayCount)
ReDim arrayJREUninstallString(strArrayCount)

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

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

'# Set this to the appropriate command line settings to do a silent MSI install
strInstallLog = strLogPath & "Java_Install_" & strComputername & ".log"
strInstallCMD = "msiexec /I """ & strInstallMSI & """ /t """ & strInstallMST & """ /QN /Lime """ & strInstallLog & """"

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

ts.WriteLine String(120, "_")
ts.WriteLine String(120, "¯")
ts.WriteLine Now() & " - Java Runtime(s) uninstallation started..."
ts.WriteLine String(120, "_") & 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)

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)

'See if it is the current version
searchCurVer = InStr(1, strDisplayName, strCurrentVersion, 1)

'If it is, Show that the current version is found
If searchCurVer > 0 Then
CurVerFound = True

ElseIf strJREUninstallString <> "" Then
'# JRE 1 found
strJREUninstallStringNEW = Replace(strJREUninstallString," -f"," -s -a /s /f")
redim Preserve arrayJREDisplayName(strArrayCount)
redim Preserve arrayJREUninstallString(strArrayCount)
arrayJREDisplayName(strArrayCount) = Now() & " - Found Old JRE: " & strDisplayName & " - Version: " & strDisplayVersion & ", Uninstalling..."
arrayJREUninstallString(strArrayCount) = strJREUninstallStringNEW
strArrayCount = strArrayCount + 1

ElseIf search7 = 0 And search1 > 0 Or search3 > 0 And search2 > 0 Then
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

redim Preserve arrayJREDisplayName(strArrayCount)
redim Preserve arrayJREUninstallString(strArrayCount)
arrayJREDisplayName(strArrayCount) = Now() & " - Found Old JRE: " & strDisplayName & " - Version: " & strDisplayVersion & ", Uninstalling..."
arrayJREUninstallString(strArrayCount) = strUninstCMD
strArrayCount = strArrayCount + 1

End If

Loop

tsIn.Close

Dim I
If CurVerFound AND strArrayCount > 0 Then
ts.Writeline Now() & " - Current Version: " & strCurrentVersion & " found, continuing with uninstalls..."
For I = LBOUND(arrayJREDisplayName) to UBOUND(arrayJREDisplayName)
ts.WriteLine arrayJREDisplayName(I)
ts.WriteLine Now() & " - Uninstall String sent: " & arrayJREUninstallString(I)
ret = wshShell.Run(arrayJREUninstallString(I) , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
Next

ElseIf CurVerFound AND strArrayCount = 0 Then
ts.WriteLine Now() & " - Current version, " & strCurrentVersion & ", found."
ts.WriteLine Now() & " - No Old Java Runtime versions are installed."
qVal = 99

ElseIf Not CurVerFound Then

ts.WriteLine Now() & " - Current Java version, " & strCurrentVersion & ", not found, installing it."
ts.WriteLine Now() & " - Running Command: " & strInstallCMD
ret = wshShell.Run(strInstallCMD , 0, True)
If ret <> 0 AND ret<> 3010 Then
ts.WriteLine Now() & " - Failed to Install Java, see " & strInstallLog & " for more details. Exiting Script."
qVal = 1
ElseIf strArrayCount > 0 Then
ts.WriteLine Now() & " - Successfully installed " & strCurrentVersion & ", and logged to " & strInstallLog & "."
For I = LBOUND(arrayJREDisplayName) to UBOUND(arrayJREDisplayName)
ts.WriteLine arrayJREDisplayName(I)
ts.WriteLine Now() & " - Uninstall String sent: " & arrayJREUninstallString(I)
ret = wshShell.Run(arrayJREUninstallString(I) , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
Next
ElseIf strArrayCount = 0 Then
ts.WriteLine Now() & " - Successfully installed " & strCurrentVersion & ", and logged to " & strInstallLog & "."
ts.WriteLine Now() & " - No Old Java Runtime versions are installed."
qVal = 99
End If
End If

ts.WriteLine String(120, "_")
ts.WriteLine String(120, "¯")
ts.Close
fso.DeleteFolder(strTempISS)
fso.DeleteFile(strTempDir & "\uninstall.tmp")

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(120, "_")
ts.WriteLine String(120, "¯")
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


Posted by: clyrigham 15 years ago
Orange Belt
1
Jean ... look that article about the return codes!

Some return codes will try to perform the installation again, other give the SMS a failed message and other return a successfully!

http://myitforum.com/cs2/blogs/mniehaus/archive/2005/03/16/4018.aspx

If everythings ocurrs fine... return "0"!

I hope this can help you!
Posted by: ComputerX 14 years ago
Yellow Belt
1
Alas, I do not code. Therefor I am limited to what I can get people to do for me.

Here is our latest version. It is slightly reworked to avoid some false positives.



'# Galen Dobbs - 13:20 23/03/2009
'# Uninstalls all but the chosen version of Java Runtime.
'# If the current version is not installed, it installs it from the specified path.
'# Based on a script by 'Daz' from Appdeploy.com message boards.
'# http://itninja.com/question/stopping-a-service09


Option Explicit

Dim wshShell, fso, strLogFile, ts, strTempDir, strTempISS, strUnString, tsIn
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, strCurrentVersion, strInstallMST
Dim searchCurVer, CurVerFound, strArrayCount, strLogPath, strInstallCMD, strInstallMSI, strInstallLog

Dim arrayJREDisplayName()
Dim arrayJREUninstallString()

'# Change this to match the version that you don't want to have it uninstall
strCurrentVersion = "Java(TM) 6 Update 13"

'# Set these to the desired log path and current version installer location
strLogPath = "\\[LogPath]\_Logs\"
strInstallMSI = "\\[InstallPath]\jre1.6.0.13.msi"
strInstallMST = "\\[InstallPath]\jre1.6.0.13.mst"

qVal = 0
strArrayCount = 0
ReDim arrayJREDisplayName(strArrayCount)
ReDim arrayJREUninstallString(strArrayCount)

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

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

'# Set this to the appropriate command line settings to do a silent MSI install
strInstallLog = strLogPath & "Java_Install_" & strComputername & ".log"
strInstallCMD = "msiexec /I """ & strInstallMSI & """ /t """ & strInstallMST & """ /QN /Lime """ & strInstallLog & """"

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

ts.WriteLine String(120, "_")
ts.WriteLine String(120, "¯")
ts.WriteLine Now() & " - Java Runtime(s) uninstallation started..."
ts.WriteLine String(120, "_") & 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)

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)

'See if it is the current version
searchCurVer = InStr(1, strDisplayName, strCurrentVersion, 1)

'If it is, Show that the current version is found
If searchCurVer > 0 Then
CurVerFound = True

ElseIf strJREUninstallString <> "" Then
'# JRE 1 found
strJREUninstallStringNEW = Replace(strJREUninstallString," -f"," -s -a /s /f")
redim Preserve arrayJREDisplayName(strArrayCount)
redim Preserve arrayJREUninstallString(strArrayCount)
arrayJREDisplayName(strArrayCount) = " - Found Old JRE: " & strDisplayName & " - Version: " & strDisplayVersion & ", Uninstalling..."
arrayJREUninstallString(strArrayCount) = strJREUninstallStringNEW
strArrayCount = strArrayCount + 1

ElseIf search7 = 0 And search1 > 0 Or search3 > 0 And search2 > 0 Then
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

redim Preserve arrayJREDisplayName(strArrayCount)
redim Preserve arrayJREUninstallString(strArrayCount)
arrayJREDisplayName(strArrayCount) = " - Found Old JRE: " & strDisplayName & " - Version: " & strDisplayVersion & ", Uninstalling..."
arrayJREUninstallString(strArrayCount) = strUninstCMD
strArrayCount = strArrayCount + 1

End If

Loop

tsIn.Close

Dim I
If CurVerFound AND strArrayCount > 0 Then
ts.Writeline Now() & " - Current Version: " & strCurrentVersion & " found, continuing with uninstalls..."
For I = LBOUND(arrayJREDisplayName) to UBOUND(arrayJREDisplayName)
ts.WriteLine Now() & arrayJREDisplayName(I)
ts.WriteLine Now() & " - Uninstall String sent: " & arrayJREUninstallString(I)
ret = wshShell.Run(arrayJREUninstallString(I) , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
Next

ElseIf CurVerFound AND strArrayCount = 0 Then
ts.WriteLine Now() & " - Current version, " & strCurrentVersion & ", found."
ts.WriteLine Now() & " - No Old Java Runtime versions are installed."
qVal = 99

ElseIf Not CurVerFound Then

ts.WriteLine Now() & " - Current Java version, " & strCurrentVersion & ", not found, installing it."
ts.WriteLine Now() & " - Running Command: " & strInstallCMD
ret = wshShell.Run(strInstallCMD , 0, True)
If ret <> 0 AND ret<> 3010 Then
ts.WriteLine Now() & " - Failed to Install Java, see " & strInstallLog & " for more details. Exiting Script."
qVal = 1
ElseIf strArrayCount > 0 Then
ts.WriteLine Now() & " - Successfully installed " & strCurrentVersion & ", and logged to " & strInstallLog & "."
For I = LBOUND(arrayJREDisplayName) to UBOUND(arrayJREDisplayName)
ts.WriteLine Now() & arrayJREDisplayName(I)
ts.WriteLine Now() & " - Uninstall String sent: " & arrayJREUninstallString(I)
ret = wshShell.Run(arrayJREUninstallString(I) , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
Next
ElseIf strArrayCount = 0 Then
ts.WriteLine Now() & " - Successfully installed " & strCurrentVersion & ", and logged to " & strInstallLog & "."
ts.WriteLine Now() & " - No Old Java Runtime versions are installed."
qVal = 99
End If
End If

ts.WriteLine String(120, "_")
ts.WriteLine String(120, "¯")
ts.Close
fso.DeleteFolder(strTempISS)
fso.DeleteFile(strTempDir & "\uninstall.tmp")

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(120, "_")
ts.WriteLine String(120, "¯")
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



Posted by: umaparvathy 13 years ago
Yellow Belt
1
Hi All,

Right now i'm packaging Apache 2.2.16 in Hp Server Automation tool... This code is really useful to me to uninstall all versions of apache...I'm writting a script to uninstall all versions of apache... But i couldn't understand some part of your code... Please help me out...

Here is the content of registry.tmp for java

[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{3248F0A8-6813-11D6-A77B-00B0D0150220}]
"DisplayIcon"="C:\\Program Files\\Java\\jre1.5.0_22\\\\bin\\javaws.exe"
"AuthorizedCDFPrefix"=""
"Comments"=""
"Contact"="http://java.com"
"DisplayVersion"="1.5.0.220"
"HelpLink"=hex(2):68,00,74,00,74,00,70,00,3a,00,2f,00,2f,00,6a,00,61,00,76,00,\
61,00,2e,00,63,00,6f,00,6d,00,00,00
"HelpTelephone"=""
"InstallDate"="20100324"
"InstallLocation"=""
"InstallSource"="C:\\Program Files\\Common Files\\Java\\Update\\Base Images\\jdk1.5.0.b64\\patch-jdk1.5.0_22.b03\\"
"ModifyPath"=hex(2):4d,00,73,00,69,00,45,00,78,00,65,00,63,00,2e,00,65,00,78,\
00,65,00,20,00,2f,00,49,00,7b,00,33,00,32,00,34,00,38,00,46,00,30,00,41,00,\
38,00,2d,00,36,00,38,00,31,00,33,00,2d,00,31,00,31,00,44,00,36,00,2d,00,41,\
00,37,00,37,00,42,00,2d,00,30,00,30,00,42,00,30,00,44,00,30,00,31,00,35,00,\
30,00,32,00,32,00,30,00,7d,00,00,00
"NoRepair"=dword:00000001
"Publisher"="Sun Microsystems, Inc."
"Readme"=hex(2):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\
00,46,00,69,00,6c,00,65,00,73,00,5c,00,4a,00,61,00,76,00,61,00,5c,00,6a,00,\
72,00,65,00,31,00,2e,00,35,00,2e,00,30,00,5f,00,32,00,32,00,5c,00,52,00,45,\
00,41,00,44,00,4d,00,45,00,2e,00,74,00,78,00,74,00,00,00
"Size"=""
"EstimatedSize"=dword:00026a86
"UninstallString"=hex(2):4d,00,73,00,69,00,45,00,78,00,65,00,63,00,2e,00,65,00,\
78,00,65,00,20,00,2f,00,49,00,7b,00,33,00,32,00,34,00,38,00,46,00,30,00,41,\
00,38,00,2d,00,36,00,38,00,31,00,33,00,2d,00,31,00,31,00,44,00,36,00,2d,00,\
41,00,37,00,37,00,42,00,2d,00,30,00,30,00,42,00,30,00,44,00,30,00,31,00,35,\
00,30,00,32,00,32,00,30,00,7d,00,00,00
"URLInfoAbout"="http://java.com"
"URLUpdateInfo"="http://java.sun.com"
"VersionMajor"=dword:00000001
"VersionMinor"=dword:00000005
"WindowsInstaller"=dword:00000001
"Version"=dword:01050000
"Language"=dword:00000000
"DisplayName"="J2SE Runtime Environment 5.0 Update 22"


Here is the Content of uninstall.tmp

[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{230F86C
D-B770-D07B-233E-CA7A0BE7C2F8}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{24A42B0
F-D4C7-529B-26CC-AEFC82D0BC63}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{2B6F677
1-46DA-4DEB-B738-E809A81B17F7}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{2B87710
3-4E7A-76A9-54FA-090928386EA5}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{31030E4
E-8532-4A22-B615-9F7A48F69C36}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{3248F0A
8-6813-11D6-A77B-00B0D0150150}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{3248F0A
8-6813-11D6-A77B-00B0D0150220}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{3266D4D
E-9CD0-48AC-9B2D-1D4879DB440F}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{32A3A4F
4-B792-11D6-A78A-00B0D0150220}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{340F521
E-3576-4E1A-B75C-EB0ACF751379}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{34D2AB4
0-150D-475D-AE32-BD23FB5EE355}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{35E1EC4
3-D4FC-4E4A-AAB3-20DDA27E8BB0}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{393E4C8
9-67E9-43BF-AD29-94D19F7624F7}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{3EF30B5
E-72C5-9F75-412C-854A76357ABA}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{4302B2D
D-D958-40E3-BAF3-B07FFE1978CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{459A192
5-3E15-5048-3D69-8DE5E0D818A9}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{4723f19
9-fa64-4233-8e6e-9fccc95a18ee}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{4A08656
4-70A4-624E-4C71-B5FF6879381F}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{4AC17C8
A-995C-C134-060C-06F5A46B631F}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{4C203E3
5-B5C7-4E35-9834-619668C0FFEE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{4D9D12C
D-B714-4A8F-A4AB-C33C4DD7F770}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{52E056C
5-3A1A-3489-346C-3D4D515097F5}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{53543B6
A-4143-1408-E112-D33A5041AE60}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{56C049B
E-79E9-4502-BEA7-9754A3E60F9B}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{56C8B4D
3-6EE0-1736-9D0F-D21AA1B7C6FA}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{57F1AB5
A-0B9A-4229-B231-B1516A33DCD4}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{58FA9DE
A-8C66-EEAD-DBD3-80EE16A1A01A}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{5D97A4A
7-C274-4B63-86D9-07A33435F505}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{619CDD8
A-14B6-43a1-AB6C-0F4EE48CE048}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{6675CA7
F-E51B-4F6A-99D4-F8F0124C6EAA}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{69333A0
4-5134-40A5-A055-9166A7AA1EC8}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{6E93D44
A-870D-823C-F0B2-09D96E8DE87B}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{6EF1FB2
A-DBFA-404F-972A-AECD03600615}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{716E030
6-8318-4364-8B8F-0CC4E9376BAC}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{7299052
b-02a4-4627-81f2-1818da5d550d}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{732A3F8
0-008B-4350-BD58-EC5AE98707B8}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{7526ECB
4-72A6-5309-A0EC-176BFD3D1AB9}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{770657D
0-A123-3C07-8E44-1C83EC895118}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{7921591
1-EEFD-4867-86D9-B79F215DED3F}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{7EEFC91
F-8C6A-4AF0-90C2-B4BD42C63B6B}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{7F10292
C-A190-4176-A665-A1ED3478DF86}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{837b34e
3-7c30-493c-8f6a-2b0f04e2912c}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{83FFCFC
7-88C6-41c6-8752-958A45325C82}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{84A3F36
5-81F3-2D0C-3592-514332C1745D}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{85262A0
6-2D8C-4BC1-B6ED-5A705D09CFFC}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{86493AD
D-824D-4B8E-BD72-8C5DCDC52A71}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{8A400C2
D-586C-80F4-8637-969C8E759083}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{0B36C6D6-F5D8-4EAF-BF94-4376A230AD5B}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{1109D0B3-EFA3-4553-AAED-4C3E9AD130E8}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{1142CCEC-ACA9-484B-BA90-C3A5CA1988C5}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{289FA8BC-6A8E-4341-B194-EB26B49E9F5D}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{48113C06-9BA2-4D54-A731-D1D2C5B3144A}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{5857EE21-03D0-482E-9620-5A30B314A2AE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{5A4E43D5-858F-49BD-BA72-8F30E1793060}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{69F52148-9BF6-4CDC-BF76-103DEAF3DD08}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{71127777-8B2C-4F97-AF7A-6CF8CAC8224D}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{7E9103DA-253F-41FF-9E83-7C83806C77DA}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{7F207DCA-3399-40CB-A968-6E5991B1421A}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{8CCB781A-CF6B-4FCB-B6D8-59C64DF5C6DB}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{ACB40B61-03E6-4F6F-AA5E-7B02A89E8AD3}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{B0EC5722-241F-4CDA-83B4-AA5846B6F9F4}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{C3F9A0DC-A5D1-4BB6-870E-2953E5A2487B}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{E8766951-2B6C-4022-86E8-80D2D1762B76}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{F5B70033-E79C-4569-90BF-BC9B4E4F3F46}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0011-0000-0000-0000000FF1CE}_PROPLUS_{FCD742B9-7A55-44BC-A776-F795F21FEDDC}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0015-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0015-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0016-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0016-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0018-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0018-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0019-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0019-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001A-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001A-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001B-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001B-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001F-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001F-0409-0000-0000000FF1CE}_PROPLUS_{ABDDE972-355B-4AF1-89A8-DA50B7B5C045}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001F-040C-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001F-040C-0000-0000000FF1CE}_PROPLUS_{F580DDD5-8D37-4998-968E-EBB76BB86787}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001F-0C0A-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-001F-0C0A-0000-0000000FF1CE}_PROPLUS_{187308AB-5FA7-4F14-9AB9-D290383A10D9}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-002C-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-003B-0000-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-003B-0000-0000-0000000FF1CE}_PRJPRO_{69F52148-9BF6-4CDC-BF76-103DEAF3DD08}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-003B-0000-0000-0000000FF1CE}_PRJPRO_{7F207DCA-3399-40CB-A968-6E5991B1421A}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-003B-0000-0000-0000000FF1CE}_PRJPRO_{9E73617F-2F38-4864-BD61-BB2DDFE43323}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-003B-0000-0000-0000000FF1CE}_PRJPRO_{B0EC5722-241F-4CDA-83B4-AA5846B6F9F4}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-003B-0000-0000-0000000FF1CE}_PRJPRO_{FCD742B9-7A55-44BC-A776-F795F21FEDDC}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0044-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0044-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-006E-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-006E-0409-0000-0000000FF1CE}_PROPLUS_{DE5A002D-8122-4278-A7EE-3121E7EA254E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-00B2-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-00B4-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-00B4-0409-0000-0000000FF1CE}_PRJPRO_{27A9D316-D332-433B-8EB1-1D93EE49F26D}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0115-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0115-0409-0000-0000000FF1CE}_PROPLUS_{DE5A002D-8122-4278-A7EE-3121E7EA254E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0117-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0117-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9068B2B
E-D93A-4C0A-861C-5E35E2C0E09E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{90A4040
9-6000-11D3-8CFE-0150048383C9}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{90FE5BF
C-C6C5-45D3-A7E3-463D707E2D44}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{91810AF
C-A4F8-4EBA-A5AA-B198BBC81144}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{931FDF4
F-35D0-4981-A43A-C3252690DCFB}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{99B39D4
0-5EA1-440C-BA46-5DE3FA6E8388}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9AC2D55
4-AC12-4F1F-AAB9-E6363ADE5381}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9CFA6FC
5-9C68-C109-2825-8E9995CE976B}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9F27CE3
B-CF94-3125-10AE-C0C19D36CA78}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9FDF923
E-DB53-41E4-8CE6-8DEB8301C12E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{A235751
1-D51D-EC3D-78C9-B4B2F2C53C8C}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{A6DC38F
E-7822-7F01-2DDE-69FE14F86F4E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC19485
5-F7AC-4D04-B4C9-07BA46FCB697}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-1033-7B44-A93000000001}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-2447-0000-900000000003}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-2448-0000-900000000003}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-5670-0000-900000000003}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-5760-0000-900000000003}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B332732
A-4958-41DD-B439-DDA2D32753C5}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B363D4F
3-E2AD-66D7-884E-B02802EF55CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B43357A
A-3A6D-4D94-B56E-43C44D09E548}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B639A4D
E-A375-47D3-89C3-DDCF98D992F7}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B6EC738
8-E277-4A5B-8C8F-71067A41BA64}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{C299012
A-DB39-4E9D-B360-75F83A7D5252}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{C490188
1-CA4A-48BD-BD48-C4CA87C1DD7C}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{C8B0680
B-CDAE-4809-9F91-387B6DE00F7C}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{C948C54
1-4E5A-5BE6-0549-2F621FF7AABC}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{CB2F7ED
D-9D1F-43C1-90FC-4F52EAE172A1}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{CD95F66
1-A5C4-44F5-A6AA-ECDD91C240BD}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{CE2CDD6
2-0124-36CA-84D3-9F4DCF5C5BD9}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{CEDD2E9
3-D66A-3903-CAB9-3F765C5D5D42}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{D7247BD
D-F68C-445A-9CF4-AF4ED6C3D8F0}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{D7B96D9
6-D9F4-40B7-B913-3D50BDD87C6F}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{DF54EF7
8-7231-46F8-8302-F1855F70099E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{DF6F178
9-2C07-49CB-993D-6B3D5586C34E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{E1B4287
B-D112-02F6-7E84-7CA8D8193988}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{E4EA6A5
A-E6FE-481E-81D0-958B2713B62C}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{E5623D0
5-F02B-E887-1B88-9C4237194062}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{E5BA043
0-919F-46DD-B656-0796F8A5ADFF}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{EACB261
C-5C4D-4CB4-B8CC-0EF998C5B3E8}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{EE20BC2
3-49BE-430D-9866-ABB01D81A407}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{F1555F7
9-380E-E2B4-9AC2-459831B9B52F}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{F18DB86
D-BC16-4E01-BCCE-63F62B931D82}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{F7B0E59
9-C114-4493-BC4D-D8FC7CBBABBB}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{FA9F595
0-2F2A-7340-7F34-0592DB64F7D9}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{FBE1CEA
C-5D54-6A03-A52E-E01E1F476CBE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{FD9E03B
5-AEEA-4D59-B512-6CE4AA0281D4}]

I couldn't understand what this part ll do

If Not fso.FolderExists(strTempISS) Then fso.CreateFolder(strTempISS)
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

the above code part is reading the lines from unisntall.tmp.... what would be the value of "strJRE1"
My system has 3 JRE versions... JRE 1.5.0 update 15, update 22... JRE 16 update 13
I'm getting no value in strJRE1...

What are u trying to get at this part

sJREUninstallString = 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")


strUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\UninstallString")

The uninstall string line returns empty string... How can i get the uninstall string

Please guide me...
So that i can finish my apache uninstall code...
So far what i'vedone in my code

Dim wshShell, fso, strLogPath, sTemp, strTempDir, strTempISS, tsIn, strUninstLine, CLSID, search5, search6, strJRE, strPublisher
Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strLogPath = wshShell.ExpandEnvironmentStrings("%temp%") & "\Log\"
If Not fso.FolderExists(strLogPath) Then fso.CreateFolder(strLogPath)
strLogFile = strLogPath & "Apache_Uninstall_" & strComputername & ".log"
WScript.Echo strLogFile
Set ts = fso.OpenTextFile(strLogFile, 8, True)
ts.WriteLine String(120,"_")
ts.WriteLine String(120,"-")
ts.WriteLine Now() & "apache_uninstall_" & ".log"
ts.WriteLine String(120,"_") & vbCrLf
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 ""Apache"" >> %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(120, "_")
ts.WriteLine String(120, "¯")
ts.Close

End If
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)
Do While Not tsIn.AtEndOfStream
strUninstLine = tsIn.ReadLine
CLSID = Mid(strUninstLine, 73, 38)
strPublisher = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\Publisher")


On Error Resume Next
'WScript.Echo strPublisher
intComparision = StrComp(strPublisher,"Apache Software Foundation")

'WScript.Echo displaycompare
If intComparision = 0 Then
WScript.Echo CLSID
strDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayName")
displaycompare = Instr(1,strDisplayName,"Apache HTTP Server")
If displaycompare > 0 Then


strApacheUninstallString= wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\UninstallString")
strDisplayVersion = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayVersion")
WScript.Echo strApacheUnistallString
searchCurVer = InStr(1,strDisplayVersion,"2.2.16",1)
If searchCurVer >0 Then
CurVerFound = True
WScript.Echo "Apache Http Server 2.2.16 is already installed...."

End if
End If
End if


Loop
tsIn.Close
WScript.Quit(0)





I've to proceed futher with the elseif part of currentversion... in my apache code such as

If searchCurVer > 0 Then
CurVerFound = True
ElseIf strJREUninstallString <> "" Then

For Your reference
Here is my uninstall.tmp



[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0115-0409-0000-0000000FF1CE}_PROPLUS_{DE5A002D-8122-4278-A7EE-3121E7EA254E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0117-0409-0000-0000000FF1CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9012000
0-0117-0409-0000-0000000FF1CE}_PROPLUS_{2FC4457D-409E-466F-861F-FB0CB796B53E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9068B2B
E-D93A-4C0A-861C-5E35E2C0E09E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{90A4040
9-6000-11D3-8CFE-0150048383C9}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{90FE5BF
C-C6C5-45D3-A7E3-463D707E2D44}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{91810AF
C-A4F8-4EBA-A5AA-B198BBC81144}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{931FDF4
F-35D0-4981-A43A-C3252690DCFB}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{99B39D4
0-5EA1-440C-BA46-5DE3FA6E8388}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9AC2D55
4-AC12-4F1F-AAB9-E6363ADE5381}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9CFA6FC
5-9C68-C109-2825-8E9995CE976B}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9F27CE3
B-CF94-3125-10AE-C0C19D36CA78}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{9FDF923
E-DB53-41E4-8CE6-8DEB8301C12E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{A235751
1-D51D-EC3D-78C9-B4B2F2C53C8C}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{A6DC38F
E-7822-7F01-2DDE-69FE14F86F4E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC19485
5-F7AC-4D04-B4C9-07BA46FCB697}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-1033-7B44-A93000000001}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-2447-0000-900000000003}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-2448-0000-900000000003}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-5670-0000-900000000003}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{AC76BA8
6-7AD7-5760-0000-900000000003}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B332732
A-4958-41DD-B439-DDA2D32753C5}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B363D4F
3-E2AD-66D7-884E-B02802EF55CE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B43357A
A-3A6D-4D94-B56E-43C44D09E548}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B639A4D
E-A375-47D3-89C3-DDCF98D992F7}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{B6EC738
8-E277-4A5B-8C8F-71067A41BA64}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{C299012
A-DB39-4E9D-B360-75F83A7D5252}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{DF54EF7
8-7231-46F8-8302-F1855F70099E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{DF6F178
9-2C07-49CB-993D-6B3D5586C34E}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{E1B4287
B-D112-02F6-7E84-7CA8D8193988}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{E4EA6A5
A-E6FE-481E-81D0-958B2713B62C}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{E5623D0
5-F02B-E887-1B88-9C4237194062}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{E5BA043
0-919F-46DD-B656-0796F8A5ADFF}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{EACB261
C-5C4D-4CB4-B8CC-0EF998C5B3E8}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{EE20BC2
3-49BE-430D-9866-ABB01D81A407}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{F1555F7
9-380E-E2B4-9AC2-459831B9B52F}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{F18DB86
D-BC16-4E01-BCCE-63F62B931D82}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{F7B0E59
9-C114-4493-BC4D-D8FC7CBBABBB}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{FA9F595
0-2F2A-7340-7F34-0592DB64F7D9}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{FBE1CEA
C-5D54-6A03-A52E-E01E1F476CBE}]
[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{FD9E03B
5-AEEA-4D59-B512-6CE4AA0281D4}]
"Contact"="Apache Users Mailing List"
"Publisher"="Apache Software Foundation"
"URLInfoAbout"="http://httpd.apache.org/"
"URLUpdateInfo"="http://www.apache.org/dist/httpd/binaries/win32/"
"DisplayName"="Apache HTTP Server 2.2.16"


Here is the content of Apache HTTP server in registry.tmp

[HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\windows\currentversion\uninstall\{85262A06-2D8C-4BC1-B6ED-5A705D09CFFC}]
"AuthorizedCDFPrefix"=""
"Comments"=""
"Contact"="Apache Users Mailing List"
"DisplayVersion"="2.2.16"
"HelpLink"=hex(2):68,00,74,00,74,00,70,00,3a,00,2f,00,2f,00,68,00,74,00,74,00,\
70,00,64,00,2e,00,61,00,70,00,61,00,63,00,68,00,65,00,2e,00,6f,00,72,00,67,\
00,2f,00,75,00,73,00,65,00,72,00,73,00,6c,00,69,00,73,00,74,00,2e,00,68,00,\
74,00,6d,00,6c,00,00,00
"HelpTelephone"="N/A"
"InstallDate"="20100828"
"InstallLocation"=""
"InstallSource"="C:\\Users\\kaliappu\\Desktop\\Content Factory\\"
"ModifyPath"=hex(2):4d,00,73,00,69,00,45,00,78,00,65,00,63,00,2e,00,65,00,78,\
00,65,00,20,00,2f,00,49,00,7b,00,38,00,35,00,32,00,36,00,32,00,41,00,30,00,\
36,00,2d,00,32,00,44,00,38,00,43,00,2d,00,34,00,42,00,43,00,31,00,2d,00,42,\
00,36,00,45,00,44,00,2d,00,35,00,41,00,37,00,30,00,35,00,44,00,30,00,39,00,\
43,00,46,00,46,00,43,00,7d,00,00,00
"Publisher"="Apache Software Foundation"
"Readme"=""
"Size"=""
"EstimatedSize"=dword:00008744
"UninstallString"=hex(2):4d,00,73,00,69,00,45,00,78,00,65,00,63,00,2e,00,65,00,\
78,00,65,00,20,00,2f,00,49,00,7b,00,38,00,35,00,32,00,36,00,32,00,41,00,30,\
00,36,00,2d,00,32,00,44,00,38,00,43,00,2d,00,34,00,42,00,43,00,31,00,2d,00,\
42,00,36,00,45,00,44,00,2d,00,35,00,41,00,37,00,30,00,35,00,44,00,30,00,39,\
00,43,00,46,00,46,00,43,00,7d,00,00,00
"URLInfoAbout"="http://httpd.apache.org/"
"URLUpdateInfo"="http://www.apache.org/dist/httpd/binaries/win32/"
"VersionMajor"=dword:00000002
"VersionMinor"=dword:00000002
"WindowsInstaller"=dword:00000001
"Version"=dword:02020010
"Language"=dword:00000409
"DisplayName"="Apache HTTP Server 2.2.16"



But i need to know what would be the strJREUninstallString.. based on that .. i can change the code and ll finish apache uninstall code...
Please help me out...
Thanks in advance...



Regards,
uma
Posted by: meofcourse 13 years ago
Yellow Belt
1
Thought I'd post my modification to allow for 32 bit versions of Java installed on 64 bit Vista/7/2008 machines. Basically it uses a second temp file for uninstall routines found in the WOW6432Node section of the registry and changes the formula for CLSID for these as well (an 85 character offset rather than 73). I am sure that this modification could be prettier in the code, but this is the easiest.

Btw. Thanks for the previous posts. They have helped tremendously.

'
# 32bit version on x64bit box modification by Meofcourse 03/02/2011
# Modified by D.Collins - 16:58 18/02/2009
'# Uninstalls any and all versions of Java Runtime.
'# Based on a script by 'muaddip' from Appdeploy.com message boards.
'# http://itninja.com/question/stopping-a-service09


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

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 Then qVal = 1

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
ts.WriteLine Now() & " - Uninstall String sent: " & strUninstCMD
ret = wshShell.Run(strUninstCMD , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
End If

Loop

tsIn.Close


'Now search the 64 bit Keys
Set tsIn = fso.OpenTextFile(strTempDir & "\uninstall.tmp", 1)

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



Do While Not tsIn.AtEndOfStream
strUninstLine = tsIn.ReadLine

CLSID = Mid(strUninstLine, 85, 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\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayName")
strDisplayVersion = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\DisplayVersion")
strPublisher = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\Publisher")
strUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & CLSID & "\UninstallString")

strJREUninstallString = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & strJRE1 & "\UninstallString")
strJREDisplayName = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\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, "Oracle", 1)
search3 = Instr(1, strDisplayName, "Java(TM)", 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 Then qVal = 1

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
ts.WriteLine Now() & " - Uninstall String sent: " & strUninstCMD
ret = wshShell.Run(strUninstCMD , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
End If

Loop

tsIn.Close

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

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

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 "REGEDIT /E %temp%\registry6432.tmp HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\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
wshShell.Run "cmd /c type %temp%\registry6432.tmp | find /i ""{"" | find /i ""}]"" >> %temp%\uninstall.tmp ", 0, True
wshShell.Run "cmd /c type %temp%\registry6432.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.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
Posted by: drlandau 12 years ago
Yellow Belt
1
It seems the Uninstall GUID in registry is based on the version with a common part of the GUID, so that might also be a way to test/uninstall. I tried googling for a complete list of JAVA versions and GUID's with not much luck (thanks Oracle...). Maybe someone can use this info as well.

For JRA6 the common part seems to be: {26A24AE4-039D-4CA4-87B4-2F8321*
Older versions seems to use: {3248F0A8-6813-11D6-A77B-00B0D0*

An example for JRE6 Update 30:


Set JREVersion=60
Set JREUpdate=30
Set JAVAUninstallKey={26A24AE4-039D-4CA4-87B4-2F8321%JREVersion%%JREUpdate%FF}
Set UninstallGUID=Start /Wait MsiExec.exe /qb- /norestart /x

%UninstallGUID% %JAVAUninstallKey%


Some GUID examples I found online:
{7148F0A8-6813-11D6-A77B-00B0D0142000}
{7148F0A8-6813-11D6-A77B-00B0D0142010}
{7148F0A8-6813-11D6-A77B-00B0D0142020}
{7148F0A8-6813-11D6-A77B-00B0D0142030}
{7148F0A8-6813-11D6-A77B-00B0D0142040}
{7148F0A8-6813-11D6-A77B-00B0D0142050}
{7148F0A8-6813-11D6-A77B-00B0D0142060}
{7148F0A8-6813-11D6-A77B-00B0D0142070}
{7148F0A8-6813-11D6-A77B-00B0D0142080}
{7148F0A8-6813-11D6-A77B-00B0D0142090}
{7148F0A8-6813-11D6-A77B-00B0D0142100}
{7148F0A8-6813-11D6-A77B-00B0D0142110}
{7148F0A8-6813-11D6-A77B-00B0D0142120}
{7148F0A8-6813-11D6-A77B-00B0D0142130}
{7148F0A8-6813-11D6-A77B-00B0D0142140}
{7148F0A8-6813-11D6-A77B-00B0D0142150}
{7148F0A8-6813-11D6-A77B-00B0D0142160}
{3248F0A8-6813-11D6-A77B-00B0D0150000}
{3248F0A8-6813-11D6-A77B-00B0D0150010}
{3248F0A8-6813-11D6-A77B-00B0D0150020}
{3248F0A8-6813-11D6-A77B-00B0D0150030}
{3248F0A8-6813-11D6-A77B-00B0D0150040}
{3248F0A8-6813-11D6-A77B-00B0D0150050}
{3248F0A8-6813-11D6-A77B-00B0D0150060}
{3248F0A8-6813-11D6-A77B-00B0D0150070}
{3248F0A8-6813-11D6-A77B-00B0D0150080}
{3248F0A8-6813-11D6-A77B-00B0D0150090}
{3248F0A8-6813-11D6-A77B-00B0D0150100}
{3248F0A8-6813-11D6-A77B-00B0D0150110}
{3248F0A8-6813-11D6-A77B-00B0D0150120}
{3248F0A8-6813-11D6-A77B-00B0D0150130}
{3248F0A8-6813-11D6-A77B-00B0D0150140}
{3248F0A8-6813-11D6-A77B-00B0D0160000}
{3248F0A8-6813-11D6-A77B-00B0D0160010}
{3248F0A8-6813-11D6-A77B-00B0D0160020}
{3248F0A8-6813-11D6-A77B-00B0D0160030}
{3248F0A8-6813-11D6-A77B-00B0D0160040}
{3248F0A8-6813-11D6-A77B-00B0D0160050}
{3248F0A8-6813-11D6-A77B-00B0D0160060}
{3248F0A8-6813-11D6-A77B-00B0D0160070}
{3248F0A8-6813-11D6-A77B-00B0D0160080}
{3248F0A8-6813-11D6-A77B-00B0D0160090}

{26A24AE4-039D-4CA4-87B4-2F83216010FF}
{26A24AE4-039D-4CA4-87B4-2F83216011FF}
{26A24AE4-039D-4CA4-87B4-2F83216012FF}
{26A24AE4-039D-4CA4-87B4-2F83216013FF}
{26A24AE4-039D-4CA4-87B4-2F83216014FF}
{26A24AE4-039D-4CA4-87B4-2F83216015FF}
{26A24AE4-039D-4CA4-87B4-2F83216016FF}
{26A24AE4-039D-4CA4-87B4-2F83216017FF}
{26A24AE4-039D-4CA4-87B4-2F83216018FF}
{26A24AE4-039D-4CA4-87B4-2F83216019FF}
{26A24AE4-039D-4CA4-87B4-2F83216020FF}

/Nicolaj
Posted by: tamahome 12 years ago
Purple Belt
1
This is what I ended up doing:

rem in case of broken old install
copy /y regutils.dll "C:\Program Files (x86)\Java\jre6\bin\"

rem breaks install if run twice! 2nd to last 2 numbers is version
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83216030FF}
if errorlevel 1 start /wait msiexec.exe /i jre1.6.0_30.msi /qn

rem check it's there and return error code
dir "C:\Program Files (x86)\Java\jre6\bin\new_plugin\npjp2.dll"


Great wmic tip. How about this for uninstalling all versions?

wmic product where "name like 'Java(TM) 6 Update %'" call uninstall

Comments:
  • Tamahomer has the right idea. Make it simple. Get rid of it all: All Java 5,6,7 gone. 2 lines of code.
    START /WAIT /MIN WMIC product where "Name LIKE '%%J2SE Runtime%%'" call uninstall /nointeractive
    START /WAIT /MIN WMIC product where "Name LIKE '%%Java%%'" call uninstall /nointeractive - Chad_Cooper 11 years ago
Posted by: schrotti12 9 years ago
White Belt
1

I can offer you this 3-Line-Solution:

set mycmd=reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s /f *http://java.com*
for /f " usebackq delims={} tokens=2" %%i IN (`%mycmd%`) do (
    msiexec /uninstall {%%i} /passive
)

Also documented in my Wiki:

http://en.wiki.schrotti12.eu/index.php/Remove_all_old_Java_versions


Comments:
  • This works, but it's a little careless. It removes EVERYTHING with Java in the name...such as "Visual Studio Extensions for Windows Library for JavaScript".

    I would be careful with this one. - DePingus 9 years ago
    • Yeah, you are right. I don't use this product but a more specific filter would be useful. Thanks for the hint! Maybe you can search for "http://java.com" instead of "*Java*". I tried it and it works. I changed it in the code. - schrotti12 9 years ago
Posted by: keyrage 10 years ago
White Belt
0

I've taken an approach suggested by a few people to use a WMI query but I've wrapped it up in a full powershell script that will find all 6 and 7 versions of JRE and uninstall them without any unexpected reboots from the Uninstall() method.

Its a short and clean script that will work for any Update version including any new ones that come out from Oracle.

 

See the full blog post and script at my blog site: http://24by7365.wordpress.com/2013/08/08/1823/


Comments:
  • UPDATE: New and improved version now written as a full module with switches to either specify a version to leave installed or to test the result without uninstalling anything.
    http://24by7365.wordpress.com/2014/02/07/uninstall-java-the-easy-way-redux/ - keyrage 10 years ago
  • UPDATE: Uninstall-Java 1.0 Powershell script and optional module released http://24by7365.wordpress.com/2014/08/22/uninstall-java-powershell-script-and-module-1-0-release/ - keyrage 9 years ago
Posted by: gpalau 9 years ago
Senior Yellow Belt
0
My way of uninstalling Java is not the prettiest, but it works solid, here is my take on it:


Tried to paste the code here, but IT Ninja's Interface needs work... 
Posted by: The GrandMaster 4 years ago
White Belt
0

Use this as PwershellScript


$appToMatch = '*NAME OF THE APPLICATION*'

$e=$MyInvocation.InvocationName

$pshome

$log=$env:temp+'\PSuninstall.log'



function Get-InstalledApps

{

    Log-write $log 'Start Get-InstalledApps'

    if ([IntPtr]::Size -eq 4) {

        $regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'

        Log-write $log 'Found x86'

    }

    else {

        $regpath = @(

            'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'

            'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'

        )

        Log-write $log 'Found x64'

    }

    Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName

}


Function Log-Write{

  Param ([Parameter(Mandatory=$true)][string]$LogPath, [Parameter(Mandatory=$true)][string]$LineValue) 

    

   Process{ 

     Add-Content -Path $LogPath -Value $LineValue 

   } 



Log-write $log 'Startinging script'


#if running in x86 mode restart in x64 mode.

if ($PSHome -match 'syswow')

{

    Log-write $log 'Found syswow'

    Log-write $log 'Shell to x64 version'

    start-process "C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe" -arg "-ExecutionPolicy bypass  -file $e" -Wait

    Log-write $log 'Return from x64 version; exiting'

    exit

}




$result = Get-InstalledApps | where {$_.DisplayName -like $appToMatch}

$result 


Log-write $log 'Found these isntalled apps:'

ForEach ($u in $result) 

{

    $UnInstall = $u.UninstallString 

    $UnInstall = $UnInstall.Trim()

    $UnInstall = $UnInstall -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""

    $UnInstall = $UnInstall.Trim()

    Log-write $log $UnInstall

    Log-write $log 'Start MSIExec'

    start-process "msiexec.exe" -arg "/X $UnInstall /qn /l*v $env:TEMP\$UnInstall.log" -Wait

    Log-write $log 'After MSIExec'


Posted by: Daz 15 years ago
Orange Belt
0
I can see you posted this a year ago, but I've only just found it. You've done all the hard work for me. Great work, well done.

I will be using a version of your script: can you tell me if you've found any problems with it in the wild since you posted it?

Comments:
  • Muadip - does this un-install remove all versions including Java 6 and Java 7 silently? - rchung 11 years ago
  • Muadip - I've tested your script and it worked on Win7x86 but it didn't work on Win7x64 because the Registry settings are different (Wow6432Node). I already changed it to reference this but it's still not working. - rezachin 10 years ago
  • what would i need to change to get different versions of java development kit uninstalled using the lab deploy script? - vikod 10 years ago
  • Look earlier for the post related to wmic - best verstion I've been using till now

    I use something like this:

    @echo OFF
    cls
    TITLE Automated workaround by Cuciu

    :KillIE&JavaProcesses
    echo *** This will kill Browsers and Java Processes ***
    Rem ***
    taskkill /F /IM iexplorer.exe
    taskkill /F /IM iexplore.exe
    taskkill /F /IM firefox.exe
    taskkill /F /IM chrome.exe
    taskkill /F /IM jusched.exe
    taskkill /F /IM jp2launcher.exe
    taskkill /F /IM java.exe
    taskkill /F /IM javaw.exe
    taskkill /F /IM jqs.exe

    :UninstallingOldJREVersions
    echo.************************************************************************
    echo.************************************************************************
    echo. DO NOT CLOSE THIS WINDOW
    echo. All the Java versions from your computer are being removed.
    echo.************************************************************************
    echo.************************************************************************
    wmic product where "name like 'Java(TM) 6%%'" call uninstall
    wmic product where "name like 'Java 7%%'" call uninstall

    goto END

    :END

    Works both on XP and Winds 7
    The trick on Windows 7 is to run it as Administrator (or to run wmic in Administrator Command Prompt -- wherever comes first) - cuciu 10 years ago
Posted by: ComputerX 15 years ago
Yellow Belt
0
Daz - You rock. Thanks for the script. Very pretty.

One question... I have a install base with all manner of ancient JREs. (I recently saw a 1.3 version.) I am pushing the current version with a GPO, but I would like to clean up the old ones.

Your script looks ideal, but I don't know how to exclude the current version[1] of the JRE from being uninstalled. How hard is that?

How do you use the script?

Thanks again.

Dan

[1] As of 03/18/09 it is version 6.0.120 {26A24AE4-039D-4CA4-87B4-2F83216012FF}
Posted by: anonymous_9363 15 years ago
Red Belt
0
Error-Trapping is immensely time consuming.Daz, point taken but

a) check out some of the MS scripts which feature a routine called BugAssert. It makes the job a breeze. Used once, you'll never trot out that excuse again. :)
b) my point was generic rather than specific. In your usage, it no doubt runs to completion 100% of the time. I was trying to guide folks who might adopt it for their own use that that Utopian environment may not exist.
Posted by: Daz 15 years ago
Orange Belt
0
VBScab,

Fair points, well made.

bugassert ...

I think I found what you mean: a nice simple technique Sub BugAssert (bTest, sErrMsg) - I like it. Simple solutions always appeal to me :o)

I only found the technique via the MS forums though (searched for: "bugassert" site:microsoft.com on google) but I like the idea.

Cheers,
Daz.
Posted by: anonymous_9363 15 years ago
Red Belt
0
I think I found what you mean: a nice simple technique Sub BugAssert (bTest, sErrMsg) - I like it. Simple solutions always appeal to me :o)Spot on. Nice, eh?
Posted by: JeanM 15 years ago
Senior Yellow Belt
0
Hello,

First I wanted to thank you guys for this script. I am testing deploying it via SCCM/SMS and wanted to know if it's ok to change the exit code from 99 to something else. I can follow the code, but I am not an expert, do I just change it here "qVal = 99" ?

SCCM considers 99 as a failure.

Thanks
Posted by: Daz 15 years ago
Orange Belt
0
ORIGINAL: JeanM

Hello,

do I just change it here "qVal = 99" ?

Thanks


Hi Jean,

Yes you can just change that line to determine the exit code for if the script did not find any Sun JRE versions to uninstall. I always use 99 in my scripts to mean 'Job not required or already run'.

Daz.
Posted by: Daz 15 years ago
Orange Belt
0
Jean,

Please note that Galen Dobbs' later version of my script sets qVal to 99 in more than one place.

I suggest that you, and indeed anyone using these scripts, tests, tests, tests and tests again before rolling any version of this script out to your live estate.

Regards and good luck,
Daz.
Posted by: anonymous_9363 15 years ago
Red Belt
0
Please note that Galen Dobbs' later version of my script sets qVal to 99 in more than one place.Hmmm...[criticism removed]The exit code should be contained in a Constant. That way, if someone has a requirement to use a different value, the change would only need to be made in one place.
Posted by: JeanM 15 years ago
Senior Yellow Belt
0
Thanks guys, I am using the version that doesn't install anything. So far I've been testing this script against my VM machines and deployed to a collection of test pc's via SCCM successfully.
Posted by: rmmiles 14 years ago
Yellow Belt
0
Might want to check the OS architecture and include the following reg path in the PreFlight for 64bit systems: "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall". [8|]
Posted by: yeah yeah 13 years ago
Senior Yellow Belt
0
This is an old thread but i'll try to resurrect the topic.

Whenever I try to run ComputerX latest script, it fails on:
Set fso = CreateObject("Scripting.FileSystem.Object")

I get an ActiveX 800A004c path not found errors. This happens locally and when I push via SMS.

Thoughts?
Posted by: pjgeutjens 13 years ago
Red Belt
0
Whenever I try to run ComputerX latest script, it fails on:
Set fso = CreateObject("Scripting.FileSystem.Object")


if that's copy-pasted from your script, I suggest you give the original another read...
In other words
Set fso = CreateObject("Scripting.FileSystem.Object")
Set fso = CreateObject("Scripting.FileSystemObject")

Find the difference [;)]
Posted by: yeah yeah 13 years ago
Senior Yellow Belt
0
Hmm. I'll need to look at my work computer and see how it's written. I was typing from an iPad yesterday so I may have typed it in wrong when i was responding back to the thread. Hopefully that is it. :)
Posted by: hipsterdoofus 13 years ago
Orange Senior Belt
0
I ran across this and the script is just what I need. The only problem I'm running into is this: The uninstall works fine, but on installation, it wants me to click to allow the executable to run (get a security warning).

Is there a way around this? Probably need a different implementation, but I was just running it out of a vbs script.
Posted by: anonymous_9363 13 years ago
Red Belt
0
That's an XP thing, perhaps applied via GroupPolicy? There's nothing a package can do to bypass that.
Posted by: pjgeutjens 13 years ago
Red Belt
0
it wants me to click to allow the executable to run (get a security warning).

Right-click the file that's throwing this warning, go to properties and see if there's an "Unblock" button. If there is, click it.
Another option is to try notepad <your file>:Zone.Identifier, this will show you the stream containing this value.

This has to do with the file's ZoneIdentifier telling windows it comes from an untrusted location

PJ
Posted by: pjgeutjens 13 years ago
Red Belt
0
I would be nice to see some explanation around bugassert
I think this is pretty much it:

' --- BUGASSERT (yes, it's for debugging) --------
Sub BugAssert (bTest, sErrMsg)
' BugAssert is a Bruce McKinney creation.
' It is used to test for intermediate results...
if bTest then Exit Sub
MsgBox "Error Detected by BugAssert: " & vbCr & vbCr & sErrMsg, _
vbCritical, " << BugAssert FAILED >> "
WScript.Quit
End Sub
Posted by: lyonjr 13 years ago
Yellow Belt
0
This script works great, but I have 2 different Java versions that I do not want removed. Can anyone help me with adjusting the script for that?
Posted by: hgsisbyoot 13 years ago
Yellow Belt
0
ORIGINAL: hipsterdoofus

I ran across this and the script is just what I need.  The only problem I'm running into is this:  The uninstall works fine, but on installation, it wants me to click to allow the executable to run (get a security warning). 

Is there a way around this?  Probably need a different implementation, but I was just running it out of a vbs script.


I created a batch that unchecks this bit in the registry, calls the vbs script, then rechecks the bit using this poke:
reg add "HKCU\Software\Microsoft\Internet Explorer\Download" /v RunInvalidSignatures /t Reg_Dword /d 1 /f
The recheckin doesn't seem to take effect until after a reboot but at least it lets you do the uninstall, re-install, etc.
Posted by: xyzzy.deploy 13 years ago
Yellow Belt
0
The script works great for all older versions, however I can't get it to un-install "Java(TM) 6 Update 22" or "Java(TM) 6 Update 22" . Looking at the old in c:\logs it never sees either 22 or 23 but is leaving 24 fine.

Any ideas would be a great help. Thanks in advance.
Posted by: meofcourse 13 years ago
Yellow Belt
0
ORIGINAL: xyzzy.deploy

The script works great for all older versions, however I can't get it to un-install "Java(TM) 6 Update 22" or "Java(TM) 6 Update 22" . Looking at the old in c:\logs it never sees either 22 or 23 but is leaving 24 fine.

Any ideas would be a great help. Thanks in advance.


The only thing I can think of is that you are now working on an x64 box. See my above post.
Posted by: LabDeploy 13 years ago
Senior Yellow Belt
0
First, thanks to the original creators of this script. It's pretty awesome.

Here's an updated version of the script I created for our computer labs. It's strictly an uninstall script but it will preserve a desired version. If you want to capture the script log you have to run it from a CMD file like so "cscript /nologo JavaUninstallScript.vbs >> P:\athto\logfile.txt". The script does create log files for each individual uninstall in a specified path.

Two caveats:
1. Java versions 1.3.0_05 and 1.3.1_05 to 1.3.1_20 can't be uninstalled silently. At least I couldn't find a way after a week of searching and testing. This script reflects that.
2. Java versions 1.4.0 to 1.4.1_07 have an uninstaller "bug". If you have two or more of these versions installed and uninstall one it breaks the uninstall for the others as ActPanel.dll gets removed and the other uninstallers error out on it. You have to remove the uninstall info for the other versions from the registry and reinstall them again to remove them properly. You might be able to get around this in the script by changing "SharedFile=YesToAll" to "SharedFile=NoToAll" in CreateISSFile but I haven't tested that yet. It may also leave lots of cruft on the system.


'***************************************************************************************
'Java removal script.
'Description: Removes x86 and x64 Java runtimes, except for the specified version.
'***************************************************************************************
'-----------------------------Begin Main Script--------------------------------
OPTION EXPLICIT

WScript.Echo "**********************************"
WScript.Echo "Java uninstall script started at " & Now()

Dim objWMIService, objProcessor, objProcess
Dim colProcesses
Dim strCurrentVersion

'Set Current Version so script will not remove it. This MUST match the DisplayName in the uninstall registry key for desired version.
'Since Java updates are syncronized for the most part this variable works for x86 and x64.
'If you wanted a different x64 version changing this variable between the RemoveJava calls would fix that.
'Set this to something nonsensical, like "FooBar", to remove ALL Java versions.
strCurrentVersion = "Java(TM) 6 Update 24"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (Debug)}\\.\root\cimv2")

'Get processor object. objProcessor.AddressWidth will give us bitness. Check objProcessor.AddressWidth = "32" or "64"
Set objProcessor = GetObject("winmgmts:\\.\root\cimv2:Win32_Processor='cpu0'")

'Kill processes that might prevent installs or uninstalls.
Set colProcesses = objWMIService.ExecQuery("Select Name from Win32_Process Where Name = 'jqs.exe' OR Name = 'jusched.exe' OR Name = 'jucheck.exe' OR Name = 'jp2launcher.exe' OR Name = 'java.exe'", "WQL", 48)

WScript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Checking for problematic processes."

'Set this to look for errors that aren't fatal when killing processes.
On Error Resume Next

For Each objProcess in colProcesses

   WScript.Echo "Found process " & objProcess.Name & "."

   objProcess.Terminate()

   Select Case Err.Number
       Case 0
           WScript.Echo "Killed process " & objProcess.Name & "."
       Case -2147217406
           WScript.Echo "Process " & objProcess.Name & " already closed."
       Case Else
           WScript.Echo "Could not kill process " & objProcess.Name & "! Aborting Script!"
           WScript.Quit(1)
   End Select
  
Next

'Resume normal error handling.
On Error Goto 0

WScript.Echo "Finished problematic process check."
WScript.Echo "----------------------------------"

RemoveJava "Software\Microsoft\Windows\CurrentVersion\Uninstall\", strCurrentVersion

'Reset strCurrentVersion here to set a different Java version for x64.
'strCurrentVersion = "x64 version"

If (objProcessor.AddressWidth = "64") Then
   RemoveJava "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", strCurrentVersion
End If

WScript.Echo vbCrLf & "Java uninstall script finished at " & Now()
WScript.Echo "**********************************"
'-------------------------------End Main Script--------------------------------

'---------------------------------Functions------------------------------------
Function RemoveJava(strRegistryPath, strCurrentVersion)

   Dim objWSHShell, objRegistry
   Dim aryUninstallKeys
   Dim strUninstallKey, strDisplayName, strUninstallString, strPathToLog
   Dim intUninstallReturnCode

   Set objWSHShell = CreateObject("WScript.Shell")
   Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
  
   'Set the logfile path here.
   strPathToLog = objWSHShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%") & "\logs\"
  
   'Find the Java uninstallers hiding in the uninstall key. &H80000002 = HKEY_LOCAL_MACHINE for this function call.
   objRegistry.EnumKey &H80000002, strRegistryPath, aryUninstallKeys

   'Since the RegRead will fail out if a value doesn't exist and the massive If block does our error checking we do this to save time.
   On Error Resume Next   
  
   For Each strUninstallKey In aryUninstallKeys
       'These must be reset in case the RegRead fails to return a value. This way we don't keep values for other pieces of software.
       strDisplayName = ""
       strUninstallString = ""
      
       strDisplayName = objWSHShell.RegRead("HKEY_LOCAL_MACHINE\" & strRegistryPath & strUninstallKey & "\DisplayName")
       strUninstallString = objWSHShell.RegRead("HKEY_LOCAL_MACHINE\" & strRegistryPath & strUninstallKey & "\UninstallString")
      
       'In English: If the DisplayName contains either Java OR the DisplayName contains J2SE Runtime Environment
       'AND if the DisplayName does not contain Development AND if the DisplayName does not contain JavaDB
       'AND if the DisplayName does not contain Web Start
       'AND if the DisplayName does not contain the current version
       'AND if the UnisntallString is not empty then do the if block.
       'Fun, eh?
       'You could remove the Web Start line to get rid of JWS but the uninstall string If block would have to account for that. It currently doesn't.
      
       If ((Instr(1, strDisplayName, "Java", 1) OR (Instr(1, strDisplayName, "J2SE Runtime Environment", 1))) _
           AND ((Instr(1, strDisplayName, "Development", 1) + Instr(1, strDisplayName, "JavaDB", 1)) < 1)  _
           AND (Instr(1, strDisplayName, "Web Start", 1) < 1) _
           AND (Instr(1, strDisplayName, strCurrentVersion, 1) < 1) _
           AND (strUninstallString <> "")) Then
          
           Wscript.Echo vbCrLf & "----------------------------------"
           WScript.Echo "Found version: " & strDisplayName
          
           'Look for very old JRE 1.1, 1.2.x, or 1.3.0 to 1.3.0_04 and 1.3.1 to 1.3.1_04 InstallShield installs.
           If (Instr(1, strUninstallKey, "JRE 1", 1)) Then
               strUninstallString = Replace(strUninstallString, "-f", "-a -x -y -f")
           'Look for 1.3.0_05 and 1.3.1_05 to 1.3.1_20 InstallShield based installs.
           ElseIf (Instr(1, strUninstallString, "-uninst", 1)) Then
               strUninstallString = ""
           'Look for a 1.4.0 to 1.4.1_07 InstallShield installation.
           ElseIf (Instr(1, strUninstallString, "Anytext", 1)) Then
               'Create ISS script for this install and fix the uninstall string.
               If (CreateISSFile(strUninstallKey, objWSHShell.ExpandEnvironmentStrings("%TEMP%"))) Then
                   strUninstallString = Replace(strUninstallString, "Anytext", "/s /SMS /w /f1""" & objWSHShell.ExpandEnvironmentStrings("%TEMP%") & "\" _
                   & strUninstallKey & ".iss"" /f2""" & strPathToLog & strDisplayName & "_Uninstall.txt""")
               Else
                   strUninstallString = ""
                   WScript.Echo "Could not create uninstall script for " & strDisplayName & "!"
               End If
           'Look for 1.4.2 and up MSI based InstallShield installs.
           ElseIf (Instr(1, strUninstallString, "msiexec.exe", 1)) Then
               'Create MSIEXEC uninstall string.
               strUninstallString = "MSIEXEC.EXE /X " & strUninstallKey & " /qn /norestart /l*v """ & strPathToLog & strDisplayName & "_Uninstall.txt"""
           Else
               strUninstallString = ""
           End If
          
           WScript.Echo "Uninstall string: " & strUninstallString
          
           If (strUninstallString = "") Then
               WScript.Echo strDisplayName & " could not be uninstalled."
           Else
               'Run the uninstaller.
               intUninstallReturnCode = objWSHShell.Run(strUninstallString, 0, true)
              
               WScript.Echo "Uninstall return code was: " & intUninstallReturnCode & "."
           End If
          
           WScript.Echo "----------------------------------"
          
       End If
  
   Next
  
   'Resume normal quit on error behavior.
   On Error GoTo 0
  
End Function

Function CreateISSFile(strUninstallKey, strTempPath)
   On Error Resume Next
  
   Dim objFileSystem, objUninstallScript
  
   Set objFileSystem  = CreateObject("Scripting.FileSystemObject")
  
   'Create InstallShield ISS script file for the uninstallation.
   Set objUninstallScript = objFileSystem.OpenTextFile(strTempPath & "\" & strUninstallKey & ".iss", 2, True)
  
   If (Err.Number <> 0) Then
       CreateISSFile = 0
   End If
  
   'One ugly write statement to cut down on the ammount of error checking that has to be done.
   'That SharedFile=YesToAll creates problems with versions 1.4.0 to 1.4.1_07
   objUninstallScript.Write "[InstallShield Silent]" & vbCrLf & "Version=v6.00.000" & vbCrLf & "File=Response File" & vbCrLf & "[File Transfer]" & _
       vbCrLf & "OverwrittenReadOnly=NoToAll" & vbCrLf & "[" & strUninstallKey & "-DlgOrder]" & vbCrLf & "Dlg0=" & strUninstallKey & "-SprintfBox-0" & _
       vbCrLf & "Count=2" & vbCrLf & "Dlg1=" & strUninstallKey & "-File Transfer" & vbCrLf & "[" & strUninstallKey & "-SprintfBox-0]" & vbCrLf & "Result=1" & _
       vbCrLf & "[Application]" & vbCrLf & "Name=Java 2 Runtime Environment, SE v1.4.0" & vbCrLf & "Version=1.4.0" & vbCrLf & "Company=JavaSoft" & _
       vbCrLf & "Lang=0009" &     vbCrLf & "[" & strUninstallKey & "-File Transfer]" & vbCrLf & "SharedFile=YesToAll"
      
   If (Err.Number <> 0) Then
       CreateISSFile = 0
   End If
      
   objUninstallScript.Close
  
   If (Err.Number <> 0) Then
       CreateISSFile = 0
   End If
  
      
   CreateISSFile = 1
  
End Function   

Posted by: pndragon 13 years ago
Yellow Belt
0
LabDeploy, I ran your script from 3/21/2011 today via a GPO as a computer startup script and upon a GPUPDATE /FORCE and restart of my test system, I noticed that the script did execute but unfortunately it didn't do so silently (which for right now, during my testing phase, this is a good thing). Is there a specific switch I need to add to the script's parameters to ensure that it runs silently?

Secondly, it did detect the only previous version of Java that was installed in my test system (6_18) but was unable to uninstall it and it resulted in an error
As the script runs, it detects the jqs.exe process and then says it successfully killed the jqs.exe process but goes on to report finding 6_18:
Uninstall string: MSIEXEC.EXE /X {26A24AE4-039D-4CA4-87B4-2F83216018F0} /qn /norestart /l*v "C:\logs\Java(TM) 6 Update 18_Uninstall.txt)
followed by
Uninstall return code: 1622
and after closing the final windows then comes a short series of fast computer beeps (about 10 or so).

I then looked at the C:\ drive and unfortunately there was no C:\logs\Java(TM) 6 Update 18_Uninstall.txt found.

Any idea what's going on? I appreciate the time you put into updating this script and whatever input you or anyone else may have on my issue.
Thank you.
Posted by: LabDeploy 13 years ago
Senior Yellow Belt
0
pndragon, couple of points about this version of the script.

It was originally written to be included in an SCCM deployment as part of a package of scripts that would remove Java and install the newest version. I never tested it as a startup script but I think I see what happened.

It makes a few assumptions, which isn't really a good thing for a standalone startup script. It assumes that the log file directory already exists and is writable to the user account running the script. In this case the script is writing to %SYSTEMDRIVE%\Logs as set here:

'Set the logfile path here.
strPathToLog = objWSHShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%") & "\logs\"

in the RemoveJava function. If that directory doesn't exist you'll see the 1622 errors with MSI packages. That error means MSIEXEC couldn't write to the logfile. You could modify the script to create/check for that directory but I find it's easier to run the script from a batch file and use "MD %SYSTEMDRIVE%\logs" at the top of the batch file to create the desired logging directory. Saves a lot of tedious object creation and error checking in a VBS script. Using IF EXIST in the batch file to check for the log directory is also advisable.

The script was also not designed to be run silently. As part of a SCCM package it was intended to be run when no user was present, like overnight. Running the script in batch mode "cscript /nologo /b JavaUninstallScript.vbs" will suppress any messages from the script but I don't know if it prevent a CMD window from opening. Redirecting the output using ">>" in a batch file will also suppress errors and create a log file.

As for the beeping... there I can't help you. No idea what caused that. [&:]

Hope that helps.
Posted by: Alex_Graf 9 years ago
Senior White Belt
0
Hello,
my way is also not the prettiest - but it´s easy - and cleary to read ...
copy the code - make .bat file - finished... last line i install the 1_6_33 JAVA for example...
regards

@echo off
color c
echo + + + + + + + + + + + + + + + + + +
echo +      Install JAVA 1_6_33        +
echo +    uninstall ALL other Versions +
echo + + + + + + + + + + + + + + + + + +

REM Browser beenden
taskkill /f /im iexplore.exe

REM Uninstall Java 8 Version 8.0.50 64 BIT
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F86418005FF} /qn

REM Uninstall Java 8 Version 8.0.50
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83218005FF} /qn

REM Uninstall Java 8 Version 8.0.310 64 BIT
MsiExec.exe /I{26A24AE4-039D-4CA4-87B4-2F86418031F0} /qn

REM Uninstall Java 8 Version 8.0.310
MsiExec.exe /I{26A24AE4-039D-4CA4-87B4-2F83218031F0} /qn

REM Uninstall Java 8 Version 8.0.250 64BIT
MsiExec.exe /I{26A24AE4-039D-4CA4-87B4-2F86418025F0} /qn

REM Uninstall Java 8 Version 8.0.250
MsiExec.exe /I{26A24AE4-039D-4CA4-87B4-2F83218025F0} /qn

REM Uninstall Java 8 Version 8.0.200 64 BIT
MsiExec.exe /I{26A24AE4-039D-4CA4-87B4-2F86418020F0} /qn

REM Uninstall Java 8 Version 8.0.200
MsiExec.exe /I{26A24AE4-039D-4CA4-87B4-2F83218020F0} /qn

REM Uninstall Java 8 Version 8.0.110 64 BIT
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F86418011FF} /qn

REM Uninstall Java 8 Version 8.0.110
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83218011FF} /qn

REM Uninstall Java 8 Version 8.0.0
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83218000FF} /qn

REM Uninstall Java 8 Version 8.0.0 64 BIT
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F86418000FF} /qn

REM Uninstall Java 8 Update 11
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83218011FF} /qn

REM Uninstall Java 8 Update 11 - 64 bit
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F86418011FF} /qn

REM Uninstall Java 8 Update 20
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83218020F0} /qn

REM Uninstall Java 8 Update 20 - 64 bit
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F86418020F0} /qn

REM Uninstall Java 8 Update 25
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83218025F0} /qn

REM Uninstall Java 8 Update 25 - 64 bit
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F86418025F0} /qn

REM Uninstall Java 8 Update 5
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83218005FF} /qn

REM Uninstall Java 8 Update 5 - 64 bit
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F86418005FF} /qn

REM Uninstall Java 7 Update 67
 msiexec /x {26A24AE4-039D-4CA4-87B4-2F03217067FF} /q
 
REM Uninstall Java 7 Update 60
 msiexec /x {26A24AE4-039D-4CA4-87B4-2F03217060FF} /q
 
REM Uninstall Java 7 Update 55
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217055FF} /qn
 
REM Uninstall Java 7 Update 51
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217051FF} /qn
 
REM Uninstall Java 7 Update 45
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217045FF} /qn
 
REM Uninstall Java 7 Update 40
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217040FF} /qn
 
REM Uninstall Java 7 Update 40 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417040FF} /qn
 
REM Uninstall Java 7 Update 25 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417025FF} /qn
 
REM Uninstall Java 7 Update 25
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217025FF} /qn
 
REM Uninstall Java 7 Update 21 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417021FF} /qn
 
REM Uninstall Java 7 Update 21
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217021FF} /qn
 
REM Uninstall Java 7 Update 17 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417017FF} /qn
 
REM Uninstall Java 7 Update 17
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217017FF} /qn
 
REM Uninstall Java 7 Update 16 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417016FF} /qn
 
REM Uninstall Java 7 Update 16
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217016FF} /qn
 
REM Uninstall Java 7 Update 15 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417015FF} /qn
 
REM Uninstall Java 7 Update 15
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217015FF} /qn
 
REM Uninstall Java 7 Update 14 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417014FF} /qn
 
REM Uninstall Java 7 Update 14
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217014FF} /qn
 
REM Uninstall Java 7 Update 13 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417013FF} /qn
 
REM Uninstall Java 7 Update 13
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217013FF} /qn
 
REM Uninstall Java 7 Update 12 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417012FF} /qn
 
REM Uninstall Java 7 Update 12
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217012FF} /qn
 
REM Uninstall Java 7 Update 11 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417011FF} /qn
 
REM Uninstall Java 7 Update 11
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217011FF} /qn
 
REM Uninstall Java 7 Update 10 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417010FF} /qn
 
REM Uninstall Java 7 Update 10
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217010FF} /qn
 
REM Uninstall Java 7 Update 9 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417009FF} /qn
 
REM Uninstall Java 7 Update 9
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217009FF} /qn
 
REM Uninstall Java 7 Update 8 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417008FF} /qn
 
REM Uninstall Java 7 Update 8
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217008FF} /qn
 
REM Uninstall Java 7 Update 7 – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417007FF} /qn
 
REM Uninstall Java 7 Update 7
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217007FF} /qn
 
REM Uninstall Java 7 Update 6
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217006FF} /qn
 
REM Uninstall Java 7 Update 6  – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417006FF} /qn
 
REM Uninstall Java 7 Update 5
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F83217005FF} /qn
 
REM Uninstall Java 7 Update 5  – 64 bit
 msiexec.exe /X {26A24AE4-039D-4CA4-87B4-2F86417005FF} /qn
 
REM Uninstall Java 7 Update 4 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417004FF} /qn
 
REM Uninstall Java 7 Update 4
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217004FF} /qn
 
REM Uninstall Java 7 Update 3 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417003FF} /qn
 
REM Uninstall Java 7 Update 3
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217003FF} /qn
 
REM Uninstall Java 7 Update 2 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417002FF} /qn
 
REM Uninstall Java 7 Update 2
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217002FF} /qn
 
REM Uninstall Java 7 Update 1 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417001FF} /qn
 
REM Uninstall Java 7 Update 1
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217001FF} /qn
 
REM Uninstall Java 6 Update 43
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216043FF} /qn
 
REM Uninstall Java 6 Update 43 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416043FF} /qn
 
REM Uninstall Java 6 Update 42
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216042FF} /qn
 
REM Uninstall Java 6 Update 42 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416042FF} /qn
 
REM Uninstall Java 6 Update 41
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216041FF} /qn
 
REM Uninstall Java 6 Update 41 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416041FF} /qn
 
REM Uninstall Java 6 Update 40
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216040FF} /qn
 
REM Uninstall Java 6 Update 40 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416040FF} /qn
 
REM Uninstall Java 6 Update 39
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216039FF} /qn
 
REM Uninstall Java 6 Update 39 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416039FF} /qn
 
REM Uninstall Java 6 Update 38
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216038FF} /qn
 
REM Uninstall Java 6 Update 38 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416038FF} /qn
 
REM Uninstall Java 6 Update 37
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216037FF} /qn
 
REM Uninstall Java 6 Update 37 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416037FF} /qn
 
REM Uninstall Java 6 Update 36
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216036FF} /qn
 
REM Uninstall Java 6 Update 36 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416036FF} /qn
 
REM Uninstall Java 6 Update 35
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216035FF} /qn
 
REM Uninstall Java 6 Update 35 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416035FF} /qn
 
REM Uninstall Java 6 Update 34
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216034FF} /qn
 
REM Uninstall Java 6 Update 34 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416034FF} /qn
 
REM Uninstall Java 6 Update 33
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216033FF} /qn
 
REM Uninstall Java 6 Update 33 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416033FF} /qn
 
REM Uninstall Java 6 Update 32
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216032FF} /qn
 
REM Uninstall Java 6 Update 32 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416032FF} /qn
 
REM Uninstall Java 6 Update 31 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416031FF} /qn
 
REM Uninstall Java 6 Update 31
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216031FF} /qn
 
REM Uninstall Java 6 Update 30 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416030FF} /qn
 
REM Uninstall Java 6 Update 30
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216030FF} /qn
 
REM Uninstall Java 6 Update 29 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416029FF} /qn
 
REM Uninstall Java 6 Update 29
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216029FF} /qn
 
REM Uninstall Java 6 Update 28 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416028FF} /qn
 
REM Uninstall Java 6 Update 28
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216028FF} /qn
 
REM Uninstall Java 6 Update 27 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416027FF} /qn
 
REM Uninstall Java 6 Update 27
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216027FF} /qn
 
REM Uninstall Java 6 Update 26 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416026FF} /qn
 
REM Uninstall Java 6 Update 26
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216026FF} /qn
 
REM Uninstall Java 6 Update 25 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416025FF} /qn
 
REM Uninstall Java 6 Update 25
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216025FF} /qn
 
REM Uninstall Java 6 Update 24 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416024FF} /qn
 
REM Uninstall Java 6 Update 24
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216024FF} /qn
 
REM Uninstall Java 6 Update 23 – 64 bit
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416023FF} /qn
 
REM Uninstall Java 6 Update 23
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216023FF} /qn
 
REM Uninstall Java 6 Update 22
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216022FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160220} /qn
 
REM Uninstall Java 6 Update 21
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216021FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160210} /qn
 
REM Uninstall Java 6 Update 20
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216020FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160200} /qn
 
REM Uninstall Java 6 Update 19
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216019FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160190} /qn
 
REM Uninstall Java 6 Update 18
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216018FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160180} /qn
 
REM Uninstall Java 6 Update 17
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216017FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160170} /qn
 
REM Uninstall Java 6 Update 16
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216016FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160160} /qn
 
REM Uninstall Java 6 Update 15
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216015FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160150} /qn
 
REM Uninstall Java 6 Update 14
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216014FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160140} /qn
 
REM Uninstall Java 6 Update 13
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216013FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160130} /qn
 
REM Uninstall Java 6 Update 12
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216012FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160120} /qn
 
REM Uninstall Java 6 Update 11
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216011FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160110} /qn
 
REM Uninstall Java 6 Update 10
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216010FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160100} /qn
 
REM Uninstall Java 6 Update 09
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216009FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160090} /qn
 
REM Uninstall Java 6 Update 08
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216008FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160080} /qn
 
REM Uninstall Java 6 Update 07
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216007FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160070} /qn
 
REM Uninstall Java 6 Update 06
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216006FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160060} /qn
 
REM Uninstall Java 6 Update 05
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216005FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160050} /qn
 
REM Uninstall Java 6 Update 04
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216004FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160040} /qn
 
REM Uninstall Java 6 Update 03
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216003FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160030} /qn
 
REM Uninstall Java 6 Update 02
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216002FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160020} /qn
 
REM Uninstall Java 6 Update 01
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216001FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160010} /qn
 
REM Uninstall Java 6
 msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216000FF} /qn
 msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160000} /qn
 
REM Uninstall Java 5.0
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150000} /qn
 
REM Uninstall Java 5.0 Update 1
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150010} /qn
 
REM Uninstall Java 5.0 Update 2
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150020} /qn
 
REM Uninstall Java 5.0 Update 3
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150030} /qn
 
REM Uninstall Java 5.0 Update 4
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150040} /qn
 
REM Uninstall Java 5.0 Update 5
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150050} /qn
 
REM Uninstall Java 5.0 Update 6
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150060} /qn
 
REM Uninstall Java 5.0 Update 7
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150070} /qn
 
REM Uninstall Java 5.0 Update 8
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150080} /qn
 
REM Uninstall 5.0 Java Update 9
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150090} /qn
 
REM Uninstall Java 5.0 Update 10
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150100} /qn
 
REM Uninstall Java 5.0 Update 11
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150110} /qn
 
REM Uninstall Java 5.0 Update 12
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150120} /qn
 
REM Uninstall Java 5.0 Update 13
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150130} /qn
 
REM Uninstall Java 5.0 Update 14
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150140} /qn
 
REM Uninstall Java 5.0 Update 15
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150150} /qn
 
REM Uninstall Java 5.0 Update 16
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150160} /qn
 
REM Uninstall Java 5.0 Update 17
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150170} /qn
 
REM Uninstall Java 5.0 Update 18
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150180} /qn
 
REM Uninstall Java 5.0 Update 19
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150190} /qn
 
REM Uninstall Java 5.0 Update 20
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150200} /qn
 
REM Uninstall Java 5.0 Update 21
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150210} /qn
 
REM Uninstall Java 5.0 Update 22
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150220} /q
 
REM Uninstall Java 5.0 Update 23
 MsiExec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0150230} /qn
 
REM Uninstall Java 1.4.2
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142000} /qn
 
REM Uninstall Java 1.4.2_01
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142010} /qn
 
REM Uninstall Java 1.4.2_02
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142020} /qn
 
REM Uninstall Java 1.4.2_03
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142030} /qn
 
REM Uninstall Java 1.4.2_04
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142040} /qn
 
REM Uninstall Java 1.4.2_05
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142050} /qn
 
REM Uninstall Java 1.4.2_106
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142060} /qn
 
REM Uninstall Java 1.4.2_07
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142070} /qn
 
REM Uninstall Java 1.4.2_08
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142080} /qn
 
REM Uninstall Java 1.4.2_09
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142090} /qn
 
REM Uninstall Java 1.4.2_10
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142100} /qn
 
REM Uninstall Java 1.4.2_11
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142110} /qn
 
REM Uninstall Java 1.4.2_12
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142120} /qn
 
REM Uninstall Java 1.4.2_13
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142130} /qn
 
REM Uninstall Java 1.4.2_14
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142140} /qn
 
REM Uninstall Java 1.4.2_15
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142150} /qn
 
REM Uninstall Java 1.4.2_16
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142160} /qn
 
REM Uninstall Java 1.4.2_17
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142170} /qn
 
REM Uninstall Java 1.4.2_18
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142180} /qn
 
REM Uninstall Java 1.4.2_19
 MsiExec.exe /x {7148F0A8-6813-11D6-A77B-00B0D0142190} /qn

MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F83216041FF} /qn
MsiExec.exe /X{26A24AE4-039D-4CA4-87B4-2F06417067FF} /qn

msiexec /i jre1.6.0_33.msi /qn ADDLOCAL=ALL REBOOT=Suppress JAVAUPDATE=0 JU=0 AUTOUPDATECHECK=0

exit
Posted by: LabDeploy 13 years ago
Senior Yellow Belt
0
Found a fantastic gotcha with SCCM on 64bit machines while testing this script. Our main deployment scenario is to 32bit machines. This script was tested on 32bit and 64bit machines as an admin user and on 32bit machines under SCCM. Worked great for our purposes. Turns out it didn't work great under SCCM on 64bit machines.

The SCCM client was running the script in a 32bit environment on a 64bit OS so all script calls to the registry were being reflected to the Wow6432Node branch. Essentially the script couldn't see the 64bit uninstall keys in the registry and was running through the 32bit uninstall keys twice. I've updated the script with a new method of calling the registry so it should always see the complete registry even when running in a 32bit environment under 64bit Windows. It's been working well in our testing so far.

I also added a bit more error output if an error does get caught and changed the InstallShield uninstall template file to NOT remove shared files. This fixes the bug with Java versions 1.4.x removing a shared file all the 1.4.x uninstallers rely on. It leaves a few DLLs on the system but the security increase of removing all old Java versions outweighs that in our environment.

Adding a bit of code to RemoveJava() to check for/create the desired logfile directory would make this pretty much a standalone removal script.

Please modify as needed. If you find a bug or add a useful modification please post it back!


'***************************************************************************************
'Java removal script.
'Version: 2.1
'Description: Removes x86 and x64 Java runtimes, except for the specified version.
'***************************************************************************************
'-----------------------------Begin Main Script--------------------------------
OPTION EXPLICIT

WScript.Echo "**********************************"
WScript.Echo "Java uninstall script started at " & Now()

Dim objWMIService, objProcessor, objProcess
Dim colProcesses
Dim strCurrentVersion

'Set Current Version so script will not remove it. This MUST match the DisplayName in the uninstall registry key for desired version.
'Since Java updates are syncronized for the most part this variable works for x86 and x64.
'If you want different x86 and x64 versions, setting the variable here sets it for the x64 version.
'Changing the variable after the first RemoveJava call will reset it for the x86 version.
'Set this to something nonsensical, like "FooBar", to remove ALL Java versions.
strCurrentVersion = "Java(TM) 6 Update 24"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (Debug)}\\.\root\cimv2")

'Get processor object. objProcessor.AddressWidth will give us bitness. Check objProcessor.AddressWidth = "32" or "64"
Set objProcessor = GetObject("winmgmts:\\.\root\cimv2:Win32_Processor='cpu0'")

'Kill processes that might prevent installs or uninstalls.
Set colProcesses = objWMIService.ExecQuery("Select Name from Win32_Process Where Name = 'jqs.exe' OR Name = 'jusched.exe' OR Name = 'jucheck.exe' OR Name = 'jp2launcher.exe' OR Name = 'java.exe' OR Name = 'javaws.exe' OR Name = 'javaw.exe'", "WQL", 48)

WScript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Checking for problematic processes."

'Set this to look for errors that aren't fatal when killing processes.
On Error Resume Next

For Each objProcess in colProcesses

WScript.Echo "Found process " & objProcess.Name & "."

objProcess.Terminate()

Select Case Err.Number
Case 0
WScript.Echo "Killed process " & objProcess.Name & "."
Err.Clear
Case -2147217406
WScript.Echo "Process " & objProcess.Name & " already closed."
Err.Clear
Case Else
WScript.Echo "Could not kill process " & objProcess.Name & "! Aborting Script!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
WScript.Quit(1)
End Select

Next

'Resume normal error handling.
On Error Goto 0

WScript.Echo "Finished problematic process check."
WScript.Echo "----------------------------------"

RemoveJava "Software\Microsoft\Windows\CurrentVersion\Uninstall\", strCurrentVersion, objProcessor

'Reset strCurrentVersion here to set a different x86 Java version on a x64 system.
'strCurrentVersion = "x86 version"

If (objProcessor.AddressWidth = "64") Then
RemoveJava "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", strCurrentVersion, objProcessor
End If

WScript.Echo vbCrLf & "Java uninstall script finished at " & Now()
WScript.Echo "**********************************"
'-------------------------------End Main Script--------------------------------

'---------------------------------Functions------------------------------------
Function RemoveJava(strRegistryPath, strCurrentVersion, objProcessor)

Dim objWSHShell, objRegistry, objWbemContext, objSWbemLocator, objSWbemServices
Dim aryUninstallKeys
Dim strUninstallKey, strDisplayName, strUninstallString, strPathToLog
Dim intUninstallReturnCode

Set objWSHShell = CreateObject("WScript.Shell")

'Set the logfile path here. This path should already exist. String needs trailing slash.
strPathToLog = objWSHShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%") & "\logs\"

'The following SWbem setup allows a script running in a x86 context, such as under the SCCM client, on a x64 system
'to access the full x64 registry. Without this the actual registry paths will be transparently redirected to the
'Wow6432Node branch for every registry call to HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall.
'Essentially this transparent redirection would hide 64bit Java runtimes from a script running in 32bit mode.

'Provides the bitness context parameters for registry calls.
Set objWbemContext = CreateObject("WbemScripting.SWbemNamedValueSet")
objWbemContext.Add "__ProviderArchitecture", objProcessor.AddressWidth
objWbemContext.Add "__RequiredArchitecture", true

'Create SWbemLocator to connect to WMI
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

'Actually connect to the WMI service using the SWbemLocator and the SWbemContext parameters.
Set objSWbemServices = objSWbemLocator.ConnectServer(".","root\default","","",,,,objWbemContext)

'Get the Standard Registry Provider from WMI... finally.
Set objRegistry = objSWbemServices.Get("StdRegProv")

'Find the Java uninstallers hiding in the uninstall key. &H80000002 = HKEY_LOCAL_MACHINE for this function call.
objRegistry.EnumKey &H80000002, strRegistryPath, aryUninstallKeys

'Enable VBS' poor excuse for error handling...
On Error Resume Next

For Each strUninstallKey In aryUninstallKeys
'These must be reset in case the RegRead fails to return a value. This way we don't keep values for other pieces of software.
strDisplayName = ""
strUninstallString = ""

'DisplayName should always be a REG_SZ
objRegistry.GetStringValue &H80000002, strRegistryPath & strUninstallKey, "DisplayName", strDisplayName

'Just in case GetStringValue doesn't retrieve what we want.
If Err.Number <> 0 Then
WScript.Echo "Could not retrieve DisplayName at " & strRegistryPath & strUninstallKey & "!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
strDisplayName = ""
Err.Clear
End If

'In English: If the DisplayName contains either Java OR the DisplayName contains J2SE Runtime Environment
'AND if the DisplayName does not contain Development AND if the DisplayName does not contain JavaDB
'AND if the DisplayName does not contain Web Start
'AND if the DisplayName does not contain the current version then do the if block.
'Fun, eh?
'You could remove the Web Start line to get rid of JWS but the uninstall string If block would have to account for that. It currently doesn't.

If ((Instr(1, strDisplayName, "Java", 1) OR (Instr(1, strDisplayName, "J2SE Runtime Environment", 1))) _
AND ((Instr(1, strDisplayName, "Development", 1) + Instr(1, strDisplayName, "JavaDB", 1)) < 1) _
AND (Instr(1, strDisplayName, "Web Start", 1) < 1) _
AND (Instr(1, strDisplayName, strCurrentVersion, 1) < 1)) Then

Wscript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Found version: " & strDisplayName
WScript.Echo "Found at: HKEY_LOCAL_MACHINE\" & strRegistryPath & strUninstallKey

'UninstallString might be a REG_EXPAND_SZ but GetStringValue should retrieve what we want.
objRegistry.GetStringValue &H80000002, strRegistryPath & strUninstallKey, "UninstallString", strUninstallString

'Just in case GetStringValue doesn't retrieve what we want.
If Err.Number <> 0 Then
WScript.Echo "Could not retrieve uninstall information for " & strDisplayName & "!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
strUninstallString = ""
Err.Clear
End If

If (strUninstallString <> "") Then
'Look for very old JRE 1.1, 1.2.x, or 1.3.0 to 1.3.0_04 and 1.3.1 to 1.3.1_04 InstallShield installs.
If (Instr(1, strUninstallKey, "JRE 1", 1)) Then
strUninstallString = Replace(strUninstallString, "-f", "-a -x -y -f")
'Look for 1.3.0_05 and 1.3.1_05 to 1.3.1_20 InstallShield based installs.
ElseIf (Instr(1, strUninstallString, "-uninst", 1)) Then
strUninstallString = ""
'Look for a 1.4.0 to 1.4.1_07 InstallShield installation.
ElseIf (Instr(1, strUninstallString, "Anytext", 1)) Then
'Create ISS script for this install and fix the uninstall string.
If (CreateISSFile(strUninstallKey, objWSHShell.ExpandEnvironmentStrings("%TEMP%"))) Then
strUninstallString = Replace(strUninstallString, "Anytext", "/s /SMS /w /f1""" & objWSHShell.ExpandEnvironmentStrings("%TEMP%") & "\" _
& strUninstallKey & ".iss"" /f2""" & strPathToLog & strDisplayName & "_Uninstall.txt""")
Else
strUninstallString = ""
End If
'Look for 1.4.2 and up MSI based InstallShield installs.
ElseIf (Instr(1, strUninstallString, "msiexec.exe", 1)) Then
'Create MSIEXEC uninstall string.
strUninstallString = "MSIEXEC.EXE /X " & strUninstallKey & " /qn /norestart /l*v """ & strPathToLog & strDisplayName & "_Uninstall.txt"""
Else
strUninstallString = ""
End If
Else
strUninstallString = ""
End If

WScript.Echo "Uninstall string: " & strUninstallString

If (strUninstallString = "") Then
WScript.Echo strDisplayName & " could not be uninstalled."
Else
'Run the uninstaller.
intUninstallReturnCode = objWSHShell.Run(strUninstallString, 0, true)
WScript.Echo "Uninstall return code was: " & intUninstallReturnCode & "."
End If

WScript.Echo "----------------------------------"

End If

Next

'Resume normal quit on error behavior.
On Error GoTo 0

End Function

Function CreateISSFile(strUninstallKey, strTempPath)
On Error Resume Next

Dim objFileSystem, objUninstallScript

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Create InstallShield ISS script file for the uninstallation.
Set objUninstallScript = objFileSystem.OpenTextFile(strTempPath & "\" & strUninstallKey & ".iss", 2, True)

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If

'One ugly write statement to cut down on the amount of error checking that has to be done.
'That SharedFile=YesToAll creates problems with multiple versions of 1.4.0 to 1.4.1_07 installed.
objUninstallScript.Write "[InstallShield Silent]" & vbCrLf & "Version=v6.00.000" & vbCrLf & "File=Response File" & vbCrLf & "[File Transfer]" & _
vbCrLf & "OverwrittenReadOnly=NoToAll" & vbCrLf & "[" & strUninstallKey & "-DlgOrder]" & vbCrLf & "Dlg0=" & strUninstallKey & "-SprintfBox-0" & _
vbCrLf & "Count=2" & vbCrLf & "Dlg1=" & strUninstallKey & "-File Transfer" & vbCrLf & "[" & strUninstallKey & "-SprintfBox-0]" & vbCrLf & "Result=1" & _
vbCrLf & "[Application]" & vbCrLf & "Name=Java 2 Runtime Environment, SE v1.4.0" & vbCrLf & "Version=1.4.0" & vbCrLf & "Company=JavaSoft" & _
vbCrLf & "Lang=0009" & vbCrLf & "[" & strUninstallKey & "-File Transfer]" & vbCrLf & "SharedFile=NoToAll"

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If

objUninstallScript.Close

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If


CreateISSFile = 1

End Function
Posted by: server_guy 13 years ago
Senior Yellow Belt
0
Is it possible to set the script so that it will keep more than 1 version of Java?

strCurrentVersion = "Java(TM) 6 Update 24"

Thanks
Posted by: LabDeploy 13 years ago
Senior Yellow Belt
0
Server_guy, here's a version that uses an array of current version strings to keep desired Java runtimes installed. The comments explain the changes.


'***************************************************************************************
'Java removal script.
'Version: 2.2
'Description: Removes x86 and x64 Java runtimes, except for the specified version.
'2011.03.09 - 2.0 - First version. Assumes %SYSTEMDRIVE%\Logs exists.
'2011.03.23 - 2.1 - Fixes issue running in 32bit SCCM under 64bit Windows.
'2011.03.30 - 2.2 - Adds array of versions to keep.
'***************************************************************************************
'-----------------------------Begin Main Script--------------------------------
OPTION EXPLICIT

WScript.Echo "**********************************"
WScript.Echo "Java uninstall script started at " & Now()

Dim objWMIService, objProcessor, objProcess
Dim colProcesses
Dim aryKeepVersions

'Create array of Java versions to leave installed.
'Each entry MUST match the DisplayName in the uninstall registry key for desired version.
'Since Java updates are syncronized for the most part this array works for x86 and x64.
'If you want different x86 and x64 versions, setting the array here sets it for x64 versions.
'Changing the array after the first RemoveJava call will reset it for x86 versions on a x64 system.
'Set this array to something nonsensical, like "FooBar", to remove ALL Java versions.
aryKeepVersions = array("Java(TM) 6 Update 24","J2SE Runtime Environment 5.0 Update 16")

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (Debug)}\\.\root\cimv2")

'Get processor object. objProcessor.AddressWidth will give us bitness. Check objProcessor.AddressWidth = "32" or "64"
Set objProcessor = GetObject("winmgmts:\\.\root\cimv2:Win32_Processor='cpu0'")

'Kill processes that might prevent installs or uninstalls.
Set colProcesses = objWMIService.ExecQuery("Select Name from Win32_Process Where Name = 'jqs.exe' OR Name = 'jusched.exe' OR Name = 'jucheck.exe' OR Name = 'jp2launcher.exe' OR Name = 'java.exe' OR Name = 'javaws.exe' OR Name = 'javaw.exe'", "WQL", 48)

WScript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Checking for problematic processes."

'Set this to look for errors that aren't fatal when killing processes.
On Error Resume Next

For Each objProcess in colProcesses

WScript.Echo "Found process " & objProcess.Name & "."

objProcess.Terminate()

Select Case Err.Number
Case 0
WScript.Echo "Killed process " & objProcess.Name & "."
Err.Clear
Case -2147217406
WScript.Echo "Process " & objProcess.Name & " already closed."
Err.Clear
Case Else
WScript.Echo "Could not kill process " & objProcess.Name & "! Aborting Script!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
WScript.Quit(1)
End Select

Next

'Resume normal error handling.
On Error Goto 0

WScript.Echo "Finished problematic process check."
WScript.Echo "----------------------------------"

'This call will remove x64 versions on a x64 system and x86 versions on a x86 system.
RemoveJava "Software\Microsoft\Windows\CurrentVersion\Uninstall\", aryKeepVersions, objProcessor

'Reset the aryKeepVersions array here to set different x86 Java versions to keep on a x64 system.
'aryKeepVersions = array("Version1", "Version2")

'This call will remove x86 versions on a x64 system.
If (objProcessor.AddressWidth = "64") Then
RemoveJava "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", aryKeepVersions, objProcessor
End If

WScript.Echo vbCrLf & "Java uninstall script finished at " & Now()
WScript.Echo "**********************************"
'-------------------------------End Main Script--------------------------------

'---------------------------------Functions------------------------------------
Function RemoveJava(strRegistryPath, aryKeepVersions, objProcessor)

Dim objWSHShell, objRegistry, objWbemContext, objSWbemLocator, objSWbemServices
Dim aryUninstallKeys
Dim strUninstallKey, strDisplayName, strUninstallString, strPathToLog, strCurrentVersion
Dim intUninstallReturnCode

Set objWSHShell = CreateObject("WScript.Shell")

'Set the logfile path here. This path should already exist. String needs trailing slash.
strPathToLog = objWSHShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%") & "\logs\"

'The following SWbem setup allows a script running in a x86 context, such as under the SCCM client, on a x64 system
'to access the full x64 registry. Without this the actual registry paths will be transparently redirected to the
'Wow6432Node branch for every registry call to HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall.
'Essentially this transparent redirection would hide 64bit Java runtimes from a script running in 32bit mode on a 64bit OS.

'Provides the bitness context parameters for registry calls.
Set objWbemContext = CreateObject("WbemScripting.SWbemNamedValueSet")
objWbemContext.Add "__ProviderArchitecture", objProcessor.AddressWidth
objWbemContext.Add "__RequiredArchitecture", true

'Create SWbemLocator to connect to WMI
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

'Actually connect to the WMI service using the SWbemLocator and the SWbemContext parameters.
Set objSWbemServices = objSWbemLocator.ConnectServer(".","root\default","","",,,,objWbemContext)

'Get the Standard Registry Provider from WMI... finally.
Set objRegistry = objSWbemServices.Get("StdRegProv")

'Find the Java uninstallers hiding in the uninstall key. &H80000002 = HKEY_LOCAL_MACHINE for this function call.
objRegistry.EnumKey &H80000002, strRegistryPath, aryUninstallKeys

'Enable VBS' poor excuse for error handling...
On Error Resume Next

For Each strUninstallKey In aryUninstallKeys
'These must be reset in case the GetStringValue fails to return a value. This way we don't keep values for other pieces of software.
strDisplayName = ""
strUninstallString = ""

'DisplayName should always be a REG_SZ
objRegistry.GetStringValue &H80000002, strRegistryPath & strUninstallKey, "DisplayName", strDisplayName

'Just in case GetStringValue doesn't retrieve what we want.
If Err.Number <> 0 Then
WScript.Echo "Could not retrieve DisplayName at " & strRegistryPath & strUninstallKey & "!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
strDisplayName = ""
Err.Clear
End If

'In English: If the DisplayName contains either Java OR the DisplayName contains J2SE Runtime Environment
'AND if the DisplayName does not contain Development AND if the DisplayName does not contain JavaDB
'AND if the DisplayName does not contain Web Start
'AND if the DisplayName does not contain SAS then do the if block.
'Fun, eh?
'You could remove the Web Start line to get rid of JWS but the uninstall string If block would have to account for that. It currently doesn't.

If ((Instr(1, strDisplayName, "Java", 1) OR (Instr(1, strDisplayName, "J2SE Runtime Environment", 1))) _
AND ((Instr(1, strDisplayName, "Development", 1) + Instr(1, strDisplayName, "JavaDB", 1)) < 1) _
AND (Instr(1, strDisplayName, "Web Start", 1) < 1) _
AND (Instr(1, strDisplayName, "SAS", 1) < 1)) Then

Wscript.Echo vbCrLf & "----------------------------------"
WScript.Echo "Found version: " & strDisplayName
WScript.Echo "Found at: HKEY_LOCAL_MACHINE\" & strRegistryPath & strUninstallKey

'UninstallString might be a REG_EXPAND_SZ but GetStringValue should retrieve what we want.
objRegistry.GetStringValue &H80000002, strRegistryPath & strUninstallKey, "UninstallString", strUninstallString

'Just in case GetStringValue doesn't retrieve what we want.
If Err.Number <> 0 Then
WScript.Echo "Could not retrieve uninstall information for " & strDisplayName & "!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
strUninstallString = ""
Err.Clear
End If

'Loop through array of versions to keep and null out strUninstallString if found.
'This will cause the next If block to ignore desired versions.
For Each strCurrentVersion In aryKeepVersions
If (Instr(1, strDisplayName, strCurrentVersion, 1) > 0) Then
strUninstallString = ""
End If
Next

If (strUninstallString <> "") Then
'Look for very old JRE 1.1, 1.2.x, or 1.3.0 to 1.3.0_04 and 1.3.1 to 1.3.1_04 InstallShield installs.
If (Instr(1, strUninstallKey, "JRE 1", 1)) Then
strUninstallString = Replace(strUninstallString, "-f", "-a -x -y -f")
'Look for 1.3.0_05 and 1.3.1_05 to 1.3.1_20 InstallShield based installs.
ElseIf (Instr(1, strUninstallString, "-uninst", 1)) Then
strUninstallString = ""
'Look for a 1.4.0 to 1.4.1_07 InstallShield installation.
ElseIf (Instr(1, strUninstallString, "Anytext", 1)) Then
'Create ISS script for this install and fix the uninstall string.
If (CreateISSFile(strUninstallKey, objWSHShell.ExpandEnvironmentStrings("%TEMP%"))) Then
strUninstallString = Replace(strUninstallString, "Anytext", "/s /SMS /w /f1""" & objWSHShell.ExpandEnvironmentStrings("%TEMP%") & "\" _
& strUninstallKey & ".iss"" /f2""" & strPathToLog & strDisplayName & "_Uninstall.txt""")
Else
strUninstallString = ""
End If
'Look for 1.4.2 and up MSI based InstallShield installs.
ElseIf (Instr(1, strUninstallString, "msiexec.exe", 1)) Then
'Create MSIEXEC uninstall string.
strUninstallString = "MSIEXEC.EXE /X " & strUninstallKey & " /qn /norestart /l*v """ & strPathToLog & strDisplayName & "_Uninstall.txt"""
Else
strUninstallString = ""
End If
Else
strUninstallString = ""
End If

WScript.Echo "Uninstall string: " & strUninstallString

If (strUninstallString = "") Then
WScript.Echo strDisplayName & " could not be uninstalled."
Else
'Run the uninstaller.
intUninstallReturnCode = objWSHShell.Run(strUninstallString, 0, true)
WScript.Echo "Uninstall return code was: " & intUninstallReturnCode & "."
End If

WScript.Echo "----------------------------------"

End If

Next

'Resume normal quit on error behavior.
On Error GoTo 0

End Function

Function CreateISSFile(strUninstallKey, strTempPath)
On Error Resume Next

Dim objFileSystem, objUninstallScript

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Create InstallShield ISS script file for the uninstallation.
Set objUninstallScript = objFileSystem.OpenTextFile(strTempPath & "\" & strUninstallKey & ".iss", 2, True)

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If

'One ugly write statement to cut down on the ammount of error checking that has to be done.
'That SharedFile=YesToAll creates problems with multiple versions of 1.4.0 to 1.4.1_07 installed.
objUninstallScript.Write "[InstallShield Silent]" & vbCrLf & "Version=v6.00.000" & vbCrLf & "File=Response File" & vbCrLf & "[File Transfer]" & _
vbCrLf & "OverwrittenReadOnly=NoToAll" & vbCrLf & "[" & strUninstallKey & "-DlgOrder]" & vbCrLf & "Dlg0=" & strUninstallKey & "-SprintfBox-0" & _
vbCrLf & "Count=2" & vbCrLf & "Dlg1=" & strUninstallKey & "-File Transfer" & vbCrLf & "[" & strUninstallKey & "-SprintfBox-0]" & vbCrLf & "Result=1" & _
vbCrLf & "[Application]" & vbCrLf & "Name=Java 2 Runtime Environment, SE v1.4.0" & vbCrLf & "Version=1.4.0" & vbCrLf & "Company=JavaSoft" & _
vbCrLf & "Lang=0009" & vbCrLf & "[" & strUninstallKey & "-File Transfer]" & vbCrLf & "SharedFile=NoToAll"

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If

objUninstallScript.Close

If (Err.Number <> 0) Then
WScript.Echo "Could not create uninstall file at " & strTempPath & "\" & strUninstallKey & ".iss!"
WScript.Echo "Error Number: " & Err.Number
WScript.Echo "Error Description: " & Err.Description
Err.Clear
CreateISSFile = 0
End If


CreateISSFile = 1

End Function
Posted by: hahnwo 12 years ago
Yellow Belt
0
Newbie question. How exactly do I run this script?
Posted by: EKutsko 12 years ago
Yellow Belt
0
I have tested this script on a VM with 3 different versions installed and it works pretty good. It took me a while to figure out I had to run it from and Administrative Command Window, but once I did that it worked really well. I have to ask now how you guys are running this with SCCM. I thought it would be fairly simple, but what I did ended up not working.

I created a package with no source files. For the program for that package I put this in the command line cscript /nologo \\SCCMSERVER\source$\apps\javauninstallscript.vbs /keeponly /versions:"Java(TM) 6 Update 25" I have it set to run hidden and gave it run as administrator when a user is logged on. Can someone enlighten my on the error of my ways.

Thanks
Posted by: LabDeploy 12 years ago
Senior Yellow Belt
0
Yes, I probably should have pointed out it requires admin rights to run.

It's really best to run this script with a batch file. Frankly I never have much luck trying to run a VBS with parameters in SCCM, the parameters never take quite right for me. I also never run install or uninstall packages when a user is logged in. There's too many chances something the user does screws up the package (reboots, shutdown, is running a browser instance that blocks the plugin update, etc.). That's just me though and I'm a bit paranoid about my SCCM deployments.

You might want to make a package with the script and a CMD to run it in the SCCM program settings. (Please note I haven't actually tested this code, it's off the top of my head for example purposes. I'm also a logging freak if you can't tell.) Like so:


MD "%SYSTEMDRIVE%\SomePathToLogs"
cscript /nologo JavaUninstallScript.vbs /keeponly /versions:"Java(TM) 6 Update 25" /logfilepath:"%SYSTEMDRIVE%\SomePathToLogs" >> "%SYSTEMDRIVE%\SomePathToLogs\JavaUninstallLog.txt"
Posted by: victormr 12 years ago
Senior Yellow Belt
0
ORIGINAL: pjgeutjens

it wants me to click to allow the executable to run (get a security warning).

Right-click the file that's throwing this warning, go to properties and see if there's an "Unblock" button. If there is, click it.
Another option is to try notepad <your file>:Zone.Identifier, this will show you the stream containing this value.

This has to do with the file's ZoneIdentifier telling windows it comes from an untrusted location

PJ



You can also use the Streams utility from sysinternals. link below.

http://technet.microsoft.com/en-us/sysinternals/bb897440
Posted by: serverkudsk 12 years ago
Yellow Belt
0
Hi, this is really a good script. But can't it be made so that it install the version you have specified, as this example I have found.

The example works fine on xp but destroy the java in winodws 7 (if it is run more than 1 time.) it, can't see the version that are installed.




'# Galen Dobbs - 13:20 23/03/2009
'# Uninstalls all but the chosen version of Java Runtime.
'# If the current version is not installed, it installs it from the specified path.
'# Based on a script by 'Daz' from Appdeploy.com message boards.
'# http://itninja.com/question/stopping-a-service09


Option Explicit

Dim wshShell, fso, strLogFile, ts, strTempDir, strTempISS, strUnString, tsIn
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, strCurrentVersion, strInstallMST
Dim searchCurVer, CurVerFound, strArrayCount, strLogPath, strInstallCMD, strInstallMSI, strInstallLog

Dim arrayJREDisplayName()
Dim arrayJREUninstallString()

'# Change this to match the version that you don't want to have it uninstall
strCurrentVersion = "Java(TM) 6 Update 27"

'# Set these to the desired log path and current version installer location
strLogPath = "\\serv08\Log$\Logoff\JavaLog\"
strInstallMSI = "\\serv08\alle$\Brian Kudsk EDB\Install\Java\jre1.6.0_27.msi"
strInstallMST = "\\serv08\alle$\Brian Kudsk EDB\Install\Java\sp1033.mst"

qVal = 0
strArrayCount = 0
ReDim arrayJREDisplayName(strArrayCount)
ReDim arrayJREUninstallString(strArrayCount)

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

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

'# Set this to the appropriate command line settings to do a silent MSI install
strInstallLog = strLogPath & "Java_Install_" & strComputername & ".log"
strInstallCMD = "msiexec /I """ & strInstallMSI & """ /t """ & strInstallMST & """ /QN /Lime """ & strInstallLog & """"

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

ts.WriteLine String(120, "_")
ts.WriteLine String(120, "¯")
ts.WriteLine Now() & " - Java Runtime(s) uninstallation started..."
ts.WriteLine String(120, "_") & 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)

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)

'See if it is the current version
searchCurVer = InStr(1, strDisplayName, strCurrentVersion, 1)

'If it is, Show that the current version is found
If searchCurVer > 0 Then
CurVerFound = True

ElseIf strJREUninstallString <> "" Then
'# JRE 1 found
strJREUninstallStringNEW = Replace(strJREUninstallString," -f"," -s -a /s /f")
redim Preserve arrayJREDisplayName(strArrayCount)
redim Preserve arrayJREUninstallString(strArrayCount)
arrayJREDisplayName(strArrayCount) = " - Found Old JRE: " & strDisplayName & " - Version: " & strDisplayVersion & ", Uninstalling..."
arrayJREUninstallString(strArrayCount) = strJREUninstallStringNEW
strArrayCount = strArrayCount + 1

ElseIf search7 = 0 And search1 > 0 Or search3 > 0 And search2 > 0 Then
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

redim Preserve arrayJREDisplayName(strArrayCount)
redim Preserve arrayJREUninstallString(strArrayCount)
arrayJREDisplayName(strArrayCount) = " - Found Old JRE: " & strDisplayName & " - Version: " & strDisplayVersion & ", Uninstalling..."
arrayJREUninstallString(strArrayCount) = strUninstCMD
strArrayCount = strArrayCount + 1

End If

Loop

tsIn.Close

Dim I
If CurVerFound AND strArrayCount > 0 Then
ts.Writeline Now() & " - Current Version: " & strCurrentVersion & " found, continuing with uninstalls..."
For I = LBOUND(arrayJREDisplayName) to UBOUND(arrayJREDisplayName)
ts.WriteLine Now() & arrayJREDisplayName(I)
ts.WriteLine Now() & " - Uninstall String sent: " & arrayJREUninstallString(I)
ret = wshShell.Run(arrayJREUninstallString(I) , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
Next

ElseIf CurVerFound AND strArrayCount = 0 Then
ts.WriteLine Now() & " - Current version, " & strCurrentVersion & ", found."
ts.WriteLine Now() & " - No Old Java Runtime versions are installed."
qVal = 99

ElseIf Not CurVerFound Then

ts.WriteLine Now() & " - Current Java version, " & strCurrentVersion & ", not found, installing it."
ts.WriteLine Now() & " - Running Command: " & strInstallCMD
ret = wshShell.Run(strInstallCMD , 0, True)
If ret <> 0 AND ret<> 3010 Then
ts.WriteLine Now() & " - Failed to Install Java, see " & strInstallLog & " for more details. Exiting Script."
qVal = 1
ElseIf strArrayCount > 0 Then
ts.WriteLine Now() & " - Successfully installed " & strCurrentVersion & ", and logged to " & strInstallLog & "."
For I = LBOUND(arrayJREDisplayName) to UBOUND(arrayJREDisplayName)
ts.WriteLine Now() & arrayJREDisplayName(I)
ts.WriteLine Now() & " - Uninstall String sent: " & arrayJREUninstallString(I)
ret = wshShell.Run(arrayJREUninstallString(I) , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
Next
ElseIf strArrayCount = 0 Then
ts.WriteLine Now() & " - Successfully installed " & strCurrentVersion & ", and logged to " & strInstallLog & "."
ts.WriteLine Now() & " - No Old Java Runtime versions are installed."
qVal = 99
End If
End If

ts.WriteLine String(120, "_")
ts.WriteLine String(120, "¯")
ts.Close
fso.DeleteFolder(strTempISS)
fso.DeleteFile(strTempDir & "\uninstall.tmp")

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(120, "_")
ts.WriteLine String(120, "¯")
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

Comments:
  • I've added to your code to remove the current versions that starts with JRE 7* sting.

    wshShell.Run "cmd /c type %temp%\registry6432.tmp | find /i ""JRE 7"" >> %temp%\uninstall.tmp ", 0, True
    wshShell.Run "cmd /c type %temp%\registry.tmp | find /i ""JRE 7"" >> %temp%\uninstall.tmp ", 0, True - youngso 11 years ago
Posted by: jfisher 12 years ago
Yellow Belt
0
I ran into a big problem with this script in my environment. It doesn't properly detect the currently installed version as current. It attempts to run in the Java installer again, and when it does, it breaks the installation. The only way I've been able to fix this is to go machine to machine by hand, install the Windows Installer Cleanup Utility, and force remove the application.

Looks like this is going to be our procedure for 300 PCs every time there's an update to Java.

Trying really hard to suppress my hatred for Oracle at the moment.
Posted by: rpmax600 12 years ago
Senior Yellow Belt
0
wmic product where name="Java(TM) 6 Update 29" call uninstall [;)]
Posted by: mechaflash 12 years ago
Yellow Belt
0
I would like to share a batch script I created to execute this script. Just in case you're in a small company without AD or any other advanced methods of deployment. As long as you have psexec you can setup machine profiles via txt files and push the removal and installation of JAVA via the vbs script. For your group lists, name them GROUPusers.txt, where GROUP=a group name you would like to assign to the machines in that list. Then when you create the lists, you can use the machine names, entering each one on a new line.

EDIT: I used LabDeploy's posted script from 4/24/2011 9:30:00 PM

EDIT: Removed the multiLists variable and created a check against the _groups variable. So you no longer have to specify that its a multi-group list, it checks the _groups variable on its own and performs the correct operation.

:: Author: Mechaflash
:: Created: 02/07/12
:: Script Function:
:: Java Uninstall Old Versions and Install New Version

SETLOCAL ENABLEDELAYEDEXPANSION
SET WAIT=PING localhost -n
SET seconds= -w 1000

SET _path=C:\Path\To\Machinelists
SET _tmp=C:\Path\To\Machinelists\TMPlist.txt
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ::
:: SETUP ::
:: ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Available groups:
:: ALL,TEST,ACCT,ADMIN,TECH

REM Set '_groups' for which group of users you want to run the command against.
:: For example: SET _groups=TEST,ACCT,TECH
:: Or example: SET _groups=ALL
SET _groups=TEST,ACCT,TECH

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: ---------------------------------- PROGRAM START -------------------------------------

:MULTI_GROUP_CHECK
SET _groupCount=0
FOR %%A IN (%_groups%) DO (
SET /A _groupCount+=1
)
IF [%_groupCount%] GTR [1] (
IF EXIST "%_tmp%" DEL /Q /F "%_tmp%"
SET _file=%_tmp%
IF NOT EXIST "%_tmp%" COPY /Y nul "%_tmp%"
%WAIT% 1 %seconds%
FOR %%A IN (%_groups%) DO (
IF [%%A] GTR [] (TYPE "%_path%\%%Ausers.txt">>"%_tmp%") ELSE (GOTO:OUT)
%WAIT% 2 %seconds%
)
) ELSE (
SET _file=%_groups%
)
:OUT

C:\psexec.exe @%_file% -u admin -p adminPassword cmd.exe /C "CSCRIPT /NOLOGO C:\Path\To\JavaUninstaller.vbs"

IF EXIST "%_tmp%" DEL /Q /F "%_tmp%"

GOTO:EOF

:: ----------------------------------- PROGRAM END --------------------------------------
Posted by: SpellJammer 12 years ago
Orange Belt
0
A colleague and I struggled with this for months. We had multiple JRE versions in our organisation and needed to standardise on a single version (JRE6U29). Something else that complicated our situation was that we were running Oracle which relied on Jinitiator versions 22 and 26. Now if anyone is familiar with these systems, you would most likely be familiar with the JVM.dll issue where one has to overwrite the jinitator JVM.dll with the JRE jvm.dll file. We also needed to untick the Enable Next Generation plugin, the IE Java Applet, Hide The Java Console, Never Check For Updates, Hide The Updates Tab and Enable Hide Warning and Run With Protections under mixed mode security. We automated all of these settings with registry keys and using a deployments.properties file and a deployment.config file which is very useful. Read more info relating to this here:

http://docs.oracle.com/javase/6/docs/technotes/guides/deployment/deployment-guide/properties.html

Since we still run XP and IE7, we also had to reinstall Java Virtual machine on all of our workstations which we included in our script as well as the copying of the Oracle Jinitator JVM.dll files.

The sequence of our Script is as follows:


1. Killing IE and Java processes
2. Uninstalling all previous versions of JRE using a VB Script by means of WMI
3. Clearing the registry of the Javasoft string as this leaves traces of old versions despite uninstalling.
4. Installing Java Virtual Machine
5. Installing JRE6U29
6. Creating C:\Windows\Sun\Java\Deployment directory to copy deployment. Properties and config file.
7. Copying deployment and config files to C:\Windows\Sun\Java\Deployment
8. Backing up and renaming jvm.dll file
9. Copying new JVM.dll file
10. Disable Java plugin
11. Disable Java Auto update Tab in the Java Control panel.

Our Script Has Two Parts.

1. Batch script executed to kill processes then runs the VB script.
2. VB script uninstalls all versions of JRE then resumes the next step of the batch script

Batch Script
@echo off
cd\
cls

@ECHO Version 1.0
@ECHO Uninstall of All JRE Versions And Installation Of JRE6U29

@ECHO Authors: Nainesh Bhavan & Dylan Ogle November 2011

:KillIE&JavaProcesses
echo *** This will kill IE and Java Processes ***
Rem ***
taskkill /F /IM iexplorer.exe
taskkill /F /IM iexplore.exe
taskkill /F /IM javaw.exe
taskkill /F /IM jqs.exe
taskkill /F /IM jusched.exe

:UninstallingOldJREVersions
cd\
cls
echo *** This will uninstall older versions of JRE ***
Rem ***
call cscript %~dp0\JRERemove.vbs

:Backup&ClearRegistryForJavaSoft
start /w regedit /e "%systemroot%\JavaSoftRegBackup.reg" HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft /f

:InstallJREVersion29
cd\
cls
echo *** This installs Java 6 Update 29 ***
Rem ***
ver | find "XP" > nul
if %ERRORLEVEL% == 0 start /w %~dp0\MSJavx86.exe /c:"javatrig.exe /exe_install /l /q /qq" /q:a

/r:n
%~dp0\jre-6u29-windows-i586-s.exe /s /v"AgreeToLicense=YES IEXPLORER=0 MOZILLA=0 REBOOT=SUPRESS

JAVAUPDATE=0"

:Copying Configuration Properties Files
cd\
cls
echo *** This creates a backup of current JVM.DLL ini JINIT folders ***
Rem ***
if not exist "C:\Windows\Sun\Java\Deployment" MD "C:\Windows\Sun\Java\Deployment"
copy %~dp0\deployment.config "C:\Windows\Sun\Java\Deployment" /y
copy %~dp0\deployment.properties "C:\Windows\Sun\Java\Deployment" /y

:BackupDLL
cd\
cls
echo *** This creates a backup of current JVM.DLL ini JINIT folders ***
Rem ***
if exist "C:\Program Files\Oracle\JInitiator 1.3.1.18\bin\hotspot\jvm.dll" ren "C:\Program

Files\Oracle\JInitiator 1.3.1.18\bin\hotspot\jvm.dll" jvm.dll-old
if exist "C:\Program Files\Oracle\JInitiator 1.3.1.22\bin\hotspot\jvm.dll" ren "C:\Program

Files\Oracle\JInitiator 1.3.1.22\bin\hotspot\jvm.dll" jvm.dll-old
if exist "C:\Program Files\Oracle\JInitiator 1.3.1.26\bin\hotspot\jvm.dll" ren "C:\Program

Files\Oracle\JInitiator 1.3.1.26\bin\hotspot\jvm.dll" jvm.dll-old
if exist "C:\Program Files\Oracle\JInitiator 1.3.1.28\bin\hotspot\jvm.dll" ren "C:\Program

Files\Oracle\JInitiator 1.3.1.28\bin\hotspot\jvm.dll" jvm.dll-old

:CopyDLL
cd\
cls
echo *** Copying JVM.DLL File JINIT Folders ***
Rem ***
if exist "C:\Program Files\Oracle\JInitiator 1.3.1.18\bin\hotspot\jvm.dll-old" copy %~dp0\Fix

\jvm.dll "C:\Program Files\Oracle\JInitiator 1.3.1.18\bin\hotspot\"
if exist "C:\Program Files\Oracle\JInitiator 1.3.1.22\bin\hotspot\jvm.dll-old" copy %~dp0\Fix

\jvm.dll "C:\Program Files\Oracle\JInitiator 1.3.1.22\bin\hotspot\"
if exist "C:\Program Files\Oracle\JInitiator 1.3.1.26\bin\hotspot\jvm.dll-old" copy %~dp0\Fix

\jvm.dll "C:\Program Files\Oracle\JInitiator 1.3.1.26\bin\hotspot\"
if exist "C:\Program Files\Oracle\JInitiator 1.3.1.28\bin\hotspot\jvm.dll-old" copy %~dp0\Fix

\jvm.dll "C:\Program Files\Oracle\JInitiator 1.3.1.28\bin\hotspot\"

:DisableJavaPlugin
cd\
cls
echo *** This will disable next generation Java Plugin in Control Panel
Rem ***
regedit.exe -s %~dp0\DisableJavaPlugin.reg


:DisableJavaAutoUpdate
cd\
cls
echo *** This will disable next generation Java Plugin in Control Panel
Rem ***
REG.EXE ADD "HKLM\SOFTWARE\JavaSoft\Java Update\Policy" /v EnableJavaUpdate /t REG_DWORD /d 0 /f
REG.EXE ADD "HKLM\SOFTWARE\JavaSoft\Java Update\Policy" /v EnableAutoUpdateCheck /t REG_DWORD /d

0 /f
REG.EXE ADD "HKLM\SOFTWARE\JavaSoft\Java Update\Policy" /v NotifyDownload /t REG_DWORD /d 0 /f
REG.EXE ADD "HKLM\SOFTWARE\JavaSoft\Java Update\Policy" /v NotifyInstall /t REG_DWORD /d 0 /f
REG.EXE DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v SunJavaUpdateSched /f


VB Uninstall Script. Simple and Elegant :)

'###########Script Written By Dylan Ogle & Nainesh Bhavan - November 2011##########


'Start Script

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Uninstall Java 2 Runtime Environment, J2SE Runtime Environment
Set colJava4dot3 = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'Java 2 Runtime Environment Standard Edition %'")
For Each objSoftware in colJava4dot3
objSoftware.Uninstall()
Next


'Uninstall Java 2 Runtime Environment, J2SE Runtime Environment
Set colJava4dot3 = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'J2SE Runtime Environment %'")
For Each objSoftware in colJava4dot3
objSoftware.Uninstall()
Next

'Uninstall Java 2 Runtime Environment, SE *
Set colJava4dot3 = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'Java 2 Runtime Environment, SE %'")
For Each objSoftware in colJava4dot3
objSoftware.Uninstall()
Next

'Uninstall Java(TM) 6 Update *
Set colJava6dot = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'Java(TM) 6 Update %'")
For Each objSoftware in colJava6dot
objSoftware.Uninstall()
Next

'Uninstall Java(TM) 7 Update *
Set colJava6dot = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'Java(TM) 7 Update %'")
For Each objSoftware in colJava6dot
objSoftware.Uninstall()
Next

'Uninstall Java(TM) 7 *
Set colJava7 = objWMIService.ExecQuery("Select * from Win32_Product Where Name like 'Java(TM) %'")
For Each objSoftware in colJava7
objSoftware.Uninstall()
Next




We also used the following reg keys to automate ticks as part of the installation for our enviroment:

******Disable Auto Update*************


[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy]
"EnableJavaUpdate"=dword:00000001
"EnableAutoUpdateCheck"=dword:00000000
"NotifyDownload"=dword:00000000
"NotifyInstall"=dword:00000000


******Disable Java Plugin*************

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Plug-in\1.6.0_29]
"UseNewJavaPlugin"=dword:00000000
"UseJava2IExplorer"=dword:00000000

******Deleteing Javasoft Key Prior to installation of New JRE client*************

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft]

*******************************************************************


Keep in mind that these locations will obviously differe for different versions but the subdirectories should more or less be the same.

Our Deployment.config and Properties files that get copied to C\:/WINDOWS/Sun/Java/Deployment

http://docs.oracle.com/javase/6/docs/technotes/guides/deployment/deployment-guide/properties.html


Deployment.config
deployment.system.config=file\:C\:/WINDOWS/Sun/Java/Deployment/deployment.properties


Deployment.properties

deployment.javaws.autodownload=NEVER
deployment.javaws.autodownload.locked=
deployment.security.mixcode=HIDE_RUN
deployment.security.mixcode.locked=
deployment.console.startup.mode=HIDE
deployment.console.startup.mode.locked=

A nice final touch to this script would be for somebody to add some kind of validation to check whether the version that you are wanting to install exists on the machine and if so, only do the automations for the various ticks to the Vb portion of the script. We packaged our script with exports of our reg keys and deployment files with winrar and deployed to all of our workstations using Config Manager without any hassles. Our next challenge is finding a way to silently uninstall all versions of Jinitiator.

Hopefully some of you will find this useful.

Comments:
  • I was using the uninstall script listed here, the one that uses the Win32_Product query, then I tried it on a Windows 7 machine and found that this method has some serious drawbacks. Please take a look at the following post that explains the issue.

    http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/13/use-powershell-to-quickly-find-installed-software.aspx

    For the lazy, here is a quote.

    "The Win32_product class is not query optimized. Queries such as “select * from Win32_Product where (name like 'Sniffer%')†require WMI to use the MSI provider to enumerate all of the installed products and then parse the full list sequentially to handle the “where†clause:,

    This process initiates a consistency check of packages installed, and then verifying and repairing the installations.
    If you have an application that makes use of the Win32_Product class, you should contact the vendor to get an updated version that does not use this class.

    On Windows Server 2003, Windows Vista, and newer operating systems, querying Win32_Product will trigger Windows Installer to perform a consistency check to verify the health of the application. This consistency check could cause a repair installation to occur. You can confirm this by checking the Windows Application Event log." - stompro 11 years ago
  • Hi stompro, my script was only intended for Windows XP but if you incorporate dimitridelanghe's uninstall method adding a wildcard for version 7 should you need to uninstall certain of these versions as well then it would compliment my script perfectly for windows 7. - SpellJammer 11 years ago
Posted by: anonymous_9363 12 years ago
Red Belt
0
Good work! Have you posted this to the 'Package KB'? If not, please do.
Posted by: SpellJammer 12 years ago
Orange Belt
0
Thanks, I could only post it under notes for JRE6U29, hope this is okay.
Posted by: joakimbs 10 years ago
White Belt
0

I initially wrote this PowerShell script to auto-update Java silently, but after some testing I came across various problematic scenarios which made me look into silent uninstalls, which have now been implemented in the script. There's an -UninstallFirst parameter that, if a new version of Java is found on the java.com website, will cause Java to be uninstalled, and the new version to be installed. There is also an -UninstallOnly parameter which is most relevant to this thread. The logic in these scripts in this thread relies in either Win32_Product or the registry being parsed for a string that matches something, and, if so, uninstall the product/application.

Due to the issues mentioned with Win32_Product (it actually checks all installed products' integrity, and thus is slow, and potentially even harmful), I parse the registry, as the initial poster of the scripts does.

The string is a wildcard string, as interpreted by the -Like operator in PowerShell, and is configurable in the accompanying configuration file (technically you could use this script to uninstall any product with the uninstall string and using the -UninstallOnly parameter).

More information can be found in the article about the script here: http://www.powershelladmin.com/wiki/PowerShell_Java_Auto-Update_Script

Posted by: mveras1972 3 years ago
White Belt
0

I don't see any need for long and convoluted scripts to remove Java when you can simply use the built-in uninstall commands like:

START /WAIT /MIN WMIC product where "Name LIKE 'Java(TM) 6 Update%%'" call uninstall /nointeractive

That line works perfectly fine. 



Comments:
  • You're right now of course. When this was posted, and I followed up with my version, it was the days of Win XP, and older versions on Java included custom setup.exe and very old .exe InstallShield versions, and possibly also before WMIC existed. Since Windows 7 all compatible Java versions were Windows Installer based so then much more simplified methods (like yours) were enough. - Daz 3 years ago
Posted by: A Man Eating Duck 8 years ago
White Belt
0
START /WAIT /MIN WMIC product where "Name LIKE '%%J2SE Runtime%%'" call uninstall /nointeractive
START /WAIT /MIN WMIC product where "Name LIKE '%%Java%%'" call uninstall /nointeractive

The problem with using the second line for java removal is that it will uninstall any software that has java in it's name e.g. free javascript editor.

You will need to use something like this to make sure you are only removing java.

START /WAIT /MIN WMIC product where "Name LIKE 'J2SE Runtime%%'" call uninstall /nointeractive
START /WAIT /MIN WMIC product where "Name LIKE 'Java 6 Update%%'" call uninstall /nointeractive
START /WAIT /MIN WMIC product where "Name LIKE 'Java(TM) 6 Update%%'" call uninstall /nointeractive
START /WAIT /MIN WMIC product where "Name LIKE 'Java 7 Update%%'" call uninstall /nointeractive
START /WAIT /MIN WMIC product where "Name LIKE 'Java(TM) 7 Update%%'" call uninstall /nointeractive
START /WAIT /MIN WMIC product where "Name LIKE 'Java 8 Update%%'" call uninstall /nointeractive

Comments:
  • Can just create exclusion for any needed Java software...

    START /WAIT /MIN WMIC product where "Name LIKE '%%Java%%' AND NOT Name LIKE '%%javascript%%'" call uninstall /nointeractive - SDNBTP 8 years ago
    • While that can be done, it's still better to have a few lines to target java directly than many exceptions stopping it uninstalling current software and any future software that has java in the title. - A Man Eating Duck 8 years ago
      • I don't know about better, maybe safer if you have a lot of programs with Java in the name. I would imagine this many WMIC queries would increase run time. - SDNBTP 8 years ago
  • anyone happen to unable to uninstall java if the uninstaller cannot find the original msi file of the java if used the script?

    if uninstaller can find te original msi file, it will have no problem executing the below script.

    START /WAIT /MIN WMIC product where "Name LIKE 'Java(TM) 6 Update%%'" call uninstall /nointeractive - anonymous_126580 8 years ago
Posted by: travisray2004 11 years ago
Senior Yellow Belt
0

I am having trouble decoding this part of your script 

 

if %ERRORLEVEL% == 0 start /w %~dp0\MSJavx86.exe /c:"javatrig.exe /exe_install /l /q /qq" /q:a 

/r:n
%~dp0\jre-6u29-windows-i586-s.exe /s /v"AgreeToLicense=YES IEXPLORER=0 MOZILLA=0 REBOOT=SUPRESS 

JAVAUPDATE=0"
 
Is this required?
%~dp0\MSJavx86.exe /c:"javatrig.exe /exe_install /l /q /qq" /q:a /r:n

 


Comments:
  • Hi Travis no it wouldn't be required, that's just if you need java virtual machine on older windows XP installations. - SpellJammer 11 years ago
Posted by: SDNBTP 9 years ago
Third Degree Blue Belt
0
Not sure why everyone is writing hundred lines of code for what can be accomplished through WMIC in 2 lines of batch. It's already been posted multiple times in this thread.

START /WAIT /MIN WMIC product where "Name LIKE '%%J2SE Runtime%%'" call uninstall /nointeractive
START /WAIT /MIN WMIC product where "Name LIKE '%%Java%%'" call uninstall /nointeractive

Comments:
  • problem with the second line is that it will uninstall any software that has java in the title. e.g. free javascript editor etc. - A Man Eating Duck 8 years ago
  • > Not sure why everyone is writing hundred lines of code ....

    you need to look at how old this thread is. When I wrote the script that was posted after the OP, I needed to not just remove Windows Installer based JRE (as your lines will), but also really old InstallShield installations back to JRE 1.1x and 1.2x.

    Daz - Daz 8 years ago
Posted by: Daz 15 years ago
Orange Belt
-1
In the interest of sharing, below is pasted my Sun Java uninstall all script, originally based on the one above by muaddip. I have tightened it up a bit and it now fully logs to "C:\Logs\Java_Uninstall_%COMPUTERNAME%". It will create C:\Logs if it does not exist.

The script does not rely on any batch files as it performs the same function from within the PreFlight() sub in the script. It is self-contained and silent.

The script will exit with return codes:
99 if no Sun JRE versions were found to uninstall.
1 if an exit code from one the uninstalls was not 0 or 3010 (reboot required).



'# D.Collins - 16:58 18/02/2009
'# Uninstalls any and all versions of Java Runtime.
'# Based on a script by 'muaddip' from Appdeploy.com message boards.
'# http://itninja.com/question/stopping-a-service09


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

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 Then qVal = 1

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
ts.WriteLine Now() & " - Uninstall String sent: " & strUninstCMD
ret = wshShell.Run(strUninstCMD , 0, True)
ts.WriteLine Now() & " - Return: " & ret
If ret <> 0 And ret <> 3010 Then qVal = 1
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")

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.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


Comments:
  • Been a while since this was posted, just wondering if you have modified this to take into account 64-bit systems as well. If so I would like to see or I will modify the code to do so. - damic 11 years ago
Posted by: robmo 13 years ago
Senior Yellow Belt
-1
"(searched for: "bugassert" site:microsoft.com on google)"

When I used this search, it produced only one article and it was in German (of course the code wasn't). I would be nice to see some explanation around bugassert.

Thanks,
Rob
Posted by: JonHall 12 years ago
Senior Purple Belt
-1
Great job, LabDeploy!! After a lot of trial/error and tweaking, I managed to run your latest script from our Kace. Thank you!!!
Posted by: sunilcse04 12 years ago
Yellow Belt
-1
Great script ! Guys, Can someone modify the script to uninstall only few specific versions while not disturbing other versions of Java on a server ? We do this regularly on servers but now server count has also increased. So retrieving server names from a list within the script might also help here.
Posted by: yossiz74 12 years ago
Yellow Belt
-1
Immensely useful discussion and code. Thanks all!
Posted by: anonymous_9363 15 years ago
Red Belt
-2
Very pretty[sigh...] Whilst not wishing to belittle anybody's efforts, the script - while undoubtedly pretty and effective - is, like so many I see, almost completely without error-trapping. The drum I continually bang about scripting (and programming in general) is: assume NOTHING. Does the script create an object? Then it should check to see if it got created. Grabbing a line from a text file to a variable? Does the variable contain any data? Killing a process? Did it get killed? You get the idea.
Posted by: KevinViolette 10 years ago
5th Degree Black Belt
-2

Fantastic !  I tested with having 3 different versions of Java installed (7.4, 6.39 and 5.12)

I ran this code in a batch file to uninstall all 3 versions. (Ran from an administrative level command prompt.) Will test running as a task sequence to install the lattest version after this batch file.

@ECHOOFF
cls
TITLE Uninstalling Java 6 and 7... (x86 and x64 versions)
START /WAIT /MIN WMIC product where "Name LIKE '%%J2SE Runtime%%'" call uninstall /nointeractive
START /WAIT /MIN WMIC product where "Name LIKE '%%Java%%'" call uninstall /nointeractive
goto END

:END
exit

Comments:
  • Looks good! I'll have to implement this one and simplify my Java removal scripts. Thank you! - GeekSoldier 10 years ago
    • Note: i removed the "pause" at the end of the script....it was causing problems when deploying with SCCM. - KevinViolette 10 years ago
      • Are you not worried about the MSIInstaller reconfiguring the products when you use the Win32_Product class? Is this not an issue anymore, or did people just forget about this issue with the class? - cburfordjr 10 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ