Uninstall Java products using SCCM
-
Monday, December 10, 2012 12:04 PM
Is there any method available for uninstalling all Java related products installed in client machines?
All Replies
-
Monday, December 10, 2012 12:57 PM
Yes, just send an advertise to those workstations with the uninstall command as a program..
Remember that CM07 is like UPS it will deliver anything that you want to the workstation, it is up to you to tell it what to do.
http://www.enhansoft.com/
- Proposed As Answer by KPRDave Monday, December 10, 2012 4:57 PM
- Marked As Answer by Nicholas LiMicrosoft Contingent Staff, Moderator Friday, December 21, 2012 4:11 AM
-
Monday, December 10, 2012 2:30 PM
you can try script something like this.
1. Create sccm report to get all the MSI codes for Java versions that helps you to remove.
2.Create package/program with script given here http://eskonr.com/2011/09/sccm-ts-vb-script-to-uninstall-applications/ and advertise to remove all Java products at one go.
Please click on "vote as Helpful" if you feel this post helpful to you.
Eswar Koneti | My Tech blog: www.eskonr.com | Linkedin: Eswar Koneti- Marked As Answer by Nicholas LiMicrosoft Contingent Staff, Moderator Friday, December 21, 2012 4:11 AM
-
Monday, December 10, 2012 4:13 PM
Its a really bad idea, but you could use this for your Package/Program:
wmic product where (name like "%Java%") call uninstall
Its a bad idea because it will be very indiscriminate - literally anything with the "java" in the name will be uninstalled. In most circumstances you will want to identify exactly what software you want removed, and target only the machines that have it for removal. However, if you look at your reports and see that you really do want to install anything with "java" in the name, this would do it.
Nash
Nash Pherson, Senior Systems Consultant
http://www.nowmicro.com - http://myitforum.com/myitforumwp/author/npherson
<-- If this post was helpful, please click "Vote as Helpful".- Edited by NPherson Monday, December 10, 2012 4:13 PM
-
Thursday, December 13, 2012 4:12 PM
Hi Nithin,
I too had a need to perform this task. I found the following http://forums.whatthetech.com/index.php?showtopic=104537
I created a task sequence with 2 steps (to allow for removal of Java 6 & Java 7) using the run command line (disable 64-bit file system redirection checked - also set to continue on error) option:
Oracle Java Cleanup 1.6
cmd /c reg query hklm\software\classes\installer\products /f "java(tm) 6" /s | find "HKEY_LOCAL_MACHINE" > deljava.txt & cmd /c for /f "tokens=* delims= " %%a in (deljava.txt) do reg delete %%a /f & cmd /c del deljava.txt & cmd /c reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" /f & cmd /c reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\wow6432node\JavaSoft\Java Runtime Environment" /f
Oracle Java Cleanup 1.7
cmd /c reg query hklm\software\classes\installer\products /f "java" /s | find "HKEY_LOCAL_MACHINE" > deljava.txt & cmd /c for /f "tokens=* delims= " %%a in (deljava.txt) do reg delete %%a /f & cmd /c del deljava.txt & cmd /c reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" /f & cmd /c reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\wow6432node\JavaSoft\Java Runtime Environment" /f
This seems to work for me. You can tweak as necessary.
- Marked As Answer by Yog LiMicrosoft Contingent Staff, Moderator Tuesday, December 25, 2012 10:32 AM
-
Thursday, December 13, 2012 9:05 PMIs it just JREs? If so, what versions are in your environment? For example, if it is all 1.6's but it ranges from 13-30 then I would install the latest version of 6 and then run the uninstall right afterwards for that version. That way it will take into account every version and upgrade it to the latest and then you can uninstall that version across the board. I would normally package this with SMS Installer. If you have multiple versions like 1.5, 1.6, and 1.7 then create query based collections for those versions and do the same thing as described above for each version. If you need more explanation then please let me know.
-
Monday, January 14, 2013 2:29 PM
Thanks everyone.
I have succesfully uninstalled Java from all client machines.
There is a vbscript available in internet.
'***************************************************************************************
'-----------------------------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 IfDim 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.NamedFor 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 colProcessesWScript.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 0WScript.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 IfWScript.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 intUninstallReturnCodeSet 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 FunctionFunction 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 FunctionFunction 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
PS:- We can figure out Installed JAVA applications in our environment using following steps.Goto SCCM console à Reporting à
First use Report (Software 06A - Search for installed software) to identify list of installed Software’s in environment
Then use Report (Computers with specific software registered in Add Remove Programs) to identify the application, that should be uninstalled
Regards
Nithin
- Proposed As Answer by Vineethvel Friday, January 18, 2013 8:15 AM
-
Wednesday, January 30, 2013 6:34 PM
you are de MANNNNNN!
These Java Jerks need to get on the stick and make management of their products easier
-
Wednesday, April 24, 2013 8:49 AMWow thank you for this script!

