Share via


Uninstalling all previous versions of Java runtime environment using application supersedence in Configuration Manager

Scenario:

I have customers ask me sometimes how application supersedence works and one of the more common questions that I get around supersedence is customers who want to move up to a new major version of Java runtime environment.

A major version upgrade of Java runtime environment will not remove an older major versions that’s installed. Example: you want to upgrade Java 6 Update X to Java 7 Update X. Some early versions of Java 6 won’t be uninstalled when a newer version gets installed as well. All versions of Java 5 will require a manual uninstall when installing a newer version of Java. This is a scenario where application supersedence can help us out.

Update: Noticing a lot of comments of people saying use the WMIC method: wmic product where “X" call uninstall /nointeractive method within WMI. I don’t recommend this because when using this method it will reconfigure every product and can cause issues you can see this in the application event log.

How this can be accomplished:

There are a few things that will need to be configured for this to work. We will need an application and deployment type for Java 7 Runtime (Update 55 during this post) and an application and deployment type for Java 5/6 (All Versions) for uninstallation purpose only. All versions means we will need to create a detection method in our deployment type that will check out for any version of Java runtime 6 and 5 (You could easily check for older versions as well).

Here is my application for Java 7 Runtime is called “Java 7 Update 55”. I have one deployment type named “Java 7 Update 55”.

image

Here is my application “All Java 6/5 Runtimes (Detection / Uninstall Only) ” and my deployment type “All Java 5/6 Runtimes Uninstall Only”

image

The deployment type “All Java 5/6 Runtimes Uninstall Only” the source location for a script I created. Notice: the install program is bogus since this deployment type is not ever going to be used to install Java runtime. The uninstall program is referencing the VBScript.

image

This script will loop though the uninstall hive (x86 and x64) of the registry looking for the displayname value’s. If the displayname contains any values you enter in the AppsToUninstall.txt file the script will search for the UninstallString value. If the uninstall value contains MSIEXEC (Windows Installer based installations only), it will parse the value to get the product code. The script will then call “msiexec /X%ProductCode% /qn REBOOT=REALLYSUPPRESS” to perform the uninstall.

Here’s what I am using for Java 5/6 detection and uninstall:

image

The deployment type “All Java 5/6 Runtimes Uninstall Only” detection method is using the following:

  • HKLM - SOFTWARE\JavaSoft\Java Runtime Environment\1.6 (or)
  • HKLM - SOFTWARE\JavaSoft\Java Runtime Environment\1.6 (With this registry key is associated with a 32-bit application on 64-bit systems).
  • HKLM - SOFTWARE\JavaSoft\Java Runtime Environment\1.5 (or)
  • HKLM - SOFTWARE\JavaSoft\Java Runtime Environment\1.5 (With this registry key is associated with a 32-bit application on 64-bit systems).

This detection methods will allow us to detect either x86 or x64 based installs of Java runtime 6 or 5.

image

In the properties of the Java 7 Update 55 application, I specified a Supersedence relationship to the Java 5/6 application and used the uninstall option. When Java 7 Update 55 is being installed from ConfigMgr, it will check the detection method for the Java 5/6 deployment type and if it's detection will use the uninstall script before installing the latest Java version.

To test this out, I have a Windows 7 x64 machine that has the following installed:

  • Java Runtime Environment 5 Update 13 x64
  • Java Runtime Environment 5 Update 16 x64
  • Java Runtime Environment 5 Update 15 x86
  • Java Runtime Environment 6 Update 41 x86
  • Java Runtime Environment 6 Update 45 x64

image

I went ahead and requested the Java 7 Update 55 from the application catalog. I a made an available deployment to a user collection for this test scenario.

We can see in AppEnforce.log that the Java 5/6 deployment type was found. We will then call the uninstall command from the deployment type for Java 5/6 (The Uninstall VBScript) .

image

image

The Uninstall.vbs script will also log everything it does to %temp%\UninstallScript.log. In my case, this will be %Windir%\Temp\UninstallScript.log since the script is executed in SYSTEM context from ConfigMgr.

image

If all goes well with the uninstall of Java 5/6 (or whatever you enter in the text file), you should have the latest version of Java 7 Update 55 in add and remove programs!

image

Wrapping Up:

In this post, we went over the process of superseding all versions a Java 6/5 runtime with Java 7 Update 55. The script is available Here to Download (Use at your own risk). It’s especially important to be careful with the AppsToUninstall.txt. This does a contains search. For example, if you add just Java to the text file the script would uninstall any application that was installed by windows installer where the display name *contains* Java in it. The script should be able to work to uninstall other applications as long as they were installed by windows installer (MSI).

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of any included script samples are subject to the terms specified in the Terms of Use

Updates:

Version 1.1 (2.11.15) - The script will now close if the AppsToUnisntall.txt is not in the same directory

Version 1.2 (5.27.15) - The script will ignore empty lines in the AppsToUnisntall.txt

Comments

  • Anonymous
    January 01, 2003
    Nice. A good way to get rid of all old Java versions.
  • Anonymous
    January 01, 2003
    @AJ, i'm not sure what's going on. Can you email me the output of the log when manually run vs with sccm? use the contact request here and I will reply so you have my email.
  • Anonymous
    January 01, 2003
    It's not recommend to use the uninstall method from WMI. If you look at the event logs you will see every application is reconfigured when you use this method.
  • Anonymous
    January 01, 2003
    @BPersaud This is likely do to Java being corrupted at some point. It may have been trying to update while running if it didn't uninstall completely and left information in the registry.
  • Anonymous
    January 01, 2003
    @ Pgrantland, It is a contains search. So if you leave Java 6 Update and Java(TM) 6 Update it will remove them all.
  • Anonymous
    January 01, 2003
    The comment has been removed
  • Anonymous
    January 01, 2003
    thanks
  • Anonymous
    January 01, 2003
    @ Larry, Can you email me the log file. Frist . Last name @Microsoft.com
  • Anonymous
    January 01, 2003
    @ Jordan, Should be good now. I'm not sure what happened with the Supersedence section. I made a few edits so I may have deleted it on accident.
  • Anonymous
    January 01, 2003
    @ Jayzus, It should be easy to make a few edits to do an exact match.
  • Anonymous
    January 01, 2003
    @ jhensley, 1603 is generic. You would need to enable /l for a log. It very well could be the older version of Java is running and/or corrupted.
  • Anonymous
    January 01, 2003
    @Andy, No not currently, I may create another version where it has to match the display name rather that a contains check if I get much feedback about that being helpful on this thread.
  • Anonymous
    January 01, 2003
    @ Hugh, Definitely a good idea. It's something that would be outside scope for adding that to the script in this blog, but you can feel free to modify the script locally.
  • Anonymous
    January 01, 2003
    @discontinuity, No when choosing this is 32-bit app on x64 OS it will auto check in the SysWow.
  • Anonymous
    January 01, 2003
    @ AJ, are you deploying the script using a deployment type or package?
  • Anonymous
    January 01, 2003
    @ckuever do you have the script in the same directory as the application source? that error = Unable to detect post-uninstall.
  • Anonymous
    January 01, 2003
    @THyfere You can choose either for the uninstall I choose a script installer and for the new Java installer I believe I used MSI deployment type. and you can deploy it as required just fine.
  • Anonymous
    January 01, 2003
    and for really old devices :
    wmic product where "name like 'Java 7%%'" call uninstall /nointeractive
    wmic product where "name like 'JavaFX%%'" call uninstall /nointeractive
    wmic product where "name like 'Java(TM) 7%%'" call uninstall /nointeractive
    wmic product where "name like 'Java(tm) 6%%'" call uninstall /nointeractive
    wmic product where "name like 'J2SE Runtime Environment%%'" call uninstall /nointeractive
  • Anonymous
    January 01, 2003
    Having a bit of an issue even when just running the script manually. It does find and attempt to remove old Java but then encounters an Error 1603 which according to the interwebs is a very common problem with Java. Any suggestions on where to go from here?
  • Anonymous
    January 01, 2003
    Hey Justin. Very good write up here! I do have a question. I extracted your zipped file that has the VBS script along with the text files. As of now the latest version of Java is 7 Update 60. If I wanted to uninstall all previous version (Java 7 Update 55 and below) would I have to modify your "AppsToUninstall.txt" file to look like this...

    Java 7 Update 55
    Java 7 Update 51
    Java 7 Update 45
    Java 7 Update 40
    Java 7 Update 25
    ... and keep going until the oldest version I want to uninstall?

    Also if I just left your two lines that say...

    Java 6 Update
    Java(TM) 6 Update

    Would those two lines uninstall all Java 6 update versions completely? Thanks for your help. I'm trying to clean up my environment and delete old versions of Java that are still installed on PC's.

    Pat
  • Anonymous
    January 01, 2003
    @ ckuever, I'm not to sure what's going on there. I haven't seen this before.
  • Anonymous
    January 01, 2003
    @ Doesn't work, I would need more info on what exactly isn't working? Logs etc would be needed.
  • Anonymous
    January 01, 2003
    @ JW, review my comment of the first comments page you should not use the WMIC method because it will reconfigure every installed MSI application.
  • Anonymous
    January 01, 2003
    It tells you in the post
  • Anonymous
    January 01, 2003
    @Nick, this is the way Java's installer works now. They don't remove previous version. They give consumers a uninstall tool during a non-silent install, but that's pretty much useless when trying to silently deploy it.
  • Anonymous
    January 01, 2003
    @Mike this = Unable to detect post-uninstall.
  • Anonymous
    January 01, 2003
    Nice blog my friend. It's a really good way to get rid of all old Java versions.
  • Anonymous
    January 01, 2003
    @Nozuka and Matt Skalecki, I released v 1.1 of this script that will now exit the script if the apps to uninstall.txt isn't in the same directory. If you following the directions, this would not occur though.
  • Anonymous
    January 01, 2003
    @ Rajneesh, you the email form and I will see what I can do.
  • Anonymous
    January 01, 2003
    @Greg thanks for pointing this out will work to get an update to the script to make it skip empty lines
  • Anonymous
    January 01, 2003
    @ Tom I just released version 1.2 that will skip empty lines.
  • Anonymous
    July 03, 2014
    This script is a great concept but the fact that it will uninstall anything that contains name of app causes the script to be inconsistent. You should change it from "contains" to "equals" atleast. It's more work on the back end gathering the exact names but the outcome is much more consistent.
  • Anonymous
    July 14, 2014
    Good blog, this is a nice way to remove old Java, but unless I am missing something you are not actually using application supersedence as per the supersedence tab found in the properties of the application? Maybe you are just missing a screenshot.
  • Anonymous
    July 30, 2014
    u can use this to :
    wmic product where "name like 'Java(TM) 6%%'" call uninstall
    wmic product where "name like 'Java 7%%'" call uninstall
  • Anonymous
    August 14, 2014
    Thank you for this write up! I feel like I too, along with John, missed the application supersedence portion of this. Could you elaborate on that a little more possibly?
  • Anonymous
    September 01, 2014
    What type of Deployment Types you choose? Script Installer or MSi? Second, what if I want to deploy as required application?
  • Anonymous
    September 04, 2014
    Thanks Justin.

    It ran well except it didn't install the Old updates of Java 7. How can I do this?
  • Anonymous
    September 16, 2014
    Great work, thank you.
  • Anonymous
    October 03, 2014
    The comment has been removed
  • Anonymous
    October 20, 2014
    Hi, i am a beginner in SCCM and cannot make it running. I wonder if uninstall.vbs, which is defined on programs tab of All JAVA 5/6 Uninstall should be in the same folder as msi for a new java 7, and should i enter the proper path in "Uninstall start in" cell for this vbs script ?. On detection method tab, whether there should be this uninstall script.vbs used or i have to configure all the detection rules?
    Thanks for help.
  • Anonymous
    October 23, 2014
    This script looks like it will do what I need, to perform a universal uninstall, of previous versions of Java (before I install the latest version). When I run the script, it seems to hang, I look at the uninstall.log file, it seems to have gone thru the hive, and then has a bunch of repeating lines, "Checking for in the uninstall hive" & "Checking for in the Wow6432Node uninstall hive". It seems to not be reading from the appstouninstall.txt file.
  • Anonymous
    October 23, 2014
    The comment has been removed
  • Anonymous
    October 23, 2014
    @Justin & That fixed what I had...:) It works like a charm!! Thank you Justin!!
  • Anonymous
    November 12, 2014
    Great write up. It works perfectly. Is there a way to just add exceptions for uninstall?? For example, how can I exclude Java 7 Update 51 - 64 bit from uninstalling,
  • Anonymous
    November 17, 2014
    I always get error 0x87D00325 with SCCM 2012 R2

    explained here: https://social.technet.microsoft.com/Forums/en-US/a8a85481-9ffc-424c-ac03-1691280c3fe7/application-removal-successful-but-fails-according-to-software-center?forum=configmanagerapps

    but a simple wscript.sleep didn't fix the Problem

    Anyone else the same Problem or a Suggestion?

    Thanks.
  • Anonymous
    November 17, 2014
    @Justin Chalfant: yes i have

    both applications use the same source path

    thanks,

    ckuever
  • Anonymous
    November 17, 2014
    1st, thank you for the script. 2nd apologies for any ignorance you may encounter. I seem to be having a problem. I'm trying to deploy the script on it own as the latest Java has already been pushed. When ran manually as local admin on the same machine I have no issues, when deployed with SCCM the log returns the following (seems to point to a permissions issue but the sccm account is a domain admin.)

    Checking for Java 7 in the uninstall hive
    Java 7 Update 67 (64-bit) Found
    HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall{26A24AE4-039D-4CA4-87B4-2F06417067FF}
    Java 7 Update 67 (64-bit) Uninstall String Parsed To = /X{26A24AE4-039D-4CA4-87B4-2F06417067FF}
    Uninstall Command Is: C:Windowssystem32msiexec.exe /X{26A24AE4-039D-4CA4-87B4-2F06417067FF} /qn REBOOT=REALLYSUPPRESS
    Uninstall Finished With Exit Code 1605

    Checking for Java 7 in the Wow6432Node uninstall hive
    Java 7 Update 67 Found
    HKLMSOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall{26A24AE4-039D-4CA4-87B4-2F03217067FF}
    Java 7 Update 67 Uninstall String Parsed To = /X{26A24AE4-039D-4CA4-87B4-2F03217067FF}
    Uninstall Command Is: C:Windowssystem32msiexec.exe /X{26A24AE4-039D-4CA4-87B4-2F03217067FF} /qn REBOOT=REALLYSUPPRESS
    Uninstall Finished With Exit Code 1605
    Script complete


    SCCM
    Error Code: "0x645 (1605)"
    Error Description: "This action is only valid for products that are currently installed."
    Description: "Action failed"
  • Anonymous
    November 18, 2014
    regardless what i configure, always 0x87D00325

    SCCM 2012 R2 CU3

    old Java Versions were successfully uninstalled via the vbs script, then 0x87D00325:

    Unable to detect post-uninstall.

    do we Need some sleep commands somewhere?

    Thanks,

    ckuever
  • Anonymous
    December 09, 2014
    Really nice script. Thank you very much. It works most of the time. But app detection for the uninstall script seems to be a bit wrong.
    The deployment type “All Java 5/6 Runtimes Uninstall Only” detection method is using the following:

    " HKLM - SOFTWAREJavaSoftJava Runtime Environment1.6 (or)
    HKLM - SOFTWAREJavaSoftJava Runtime Environment1.6 (With this registry key is associated with a 32-bit application on 64-bit systems). "

    Shouldn't the second key be "HKLM - SOFTWAREWow3264NodeJavaSoftJava Runtime Environment1.6" ?

    By the way, should we add the "HKLM - SOFTWAREJavaSoftJava Runtime Environment1.7" key to app detection clause if we are to uninstall also Java 7 updates?
  • Anonymous
    December 11, 2014
    Oh! My bad! Thank you :) What about uninstalling the Java 7 detection? Should we add "HKLM - SOFTWAREJavaSoftJava Runtime Environment1.7" keys to detection rules?
  • Anonymous
    January 05, 2015
    Thanks a lot for the script! Worked for me!
  • Anonymous
    January 05, 2015
    Justin, I am having a strange issue running this script via SCCM 2012 sp1.
    When I deploy the package, the script always searches the WOW6432 registry key.
    I written some error checking which indicates it should be looking at the 64-bit key but it still pulling uninstall strings from 32bit.

    If I run the script manually from the machine, the script works flawlessly. Is there any settings I need to change in SCCM to make this run properly?

    Thanks,
    AJ
  • Anonymous
    January 05, 2015
    I was attempting to deploy it as a package.
  • Anonymous
    January 06, 2015
    Justin, I also tried to deploy the vbs as an application and got the same results.
  • Anonymous
    January 06, 2015
    Justin,

    I have figured out the issue. When I created the application, I entered "Uninstall.vbs" under Installation program. I tried with wscript.exe "Uninstall.vbs" and had same results. I later noticed the 32 bit version of wscript.exe was executing on the machine.

    Finally, I tried %windir%system32wscript.exe "Uninstall.vbs" and it was executed with the 64bit version of wscript.exe. After completion I verified everything worked as expected.

  • Anonymous
    January 20, 2015
    Little question, if there are no previous versions of Java on the computer. The deployment works or not ?

    Because, I have a case with this error : 0x87D00325(-2016410843). And, on this computer, there are no previous version of Java.
  • Anonymous
    January 22, 2015
    The comment has been removed
  • Anonymous
    January 26, 2015
    This use to work and now it doesn't with Java 8. A fix would be great....
  • Anonymous
    January 27, 2015
    @Justin Chalfant. How can I get some logs? I would love to use this. At first it wouldn't uninstall version 8 at all. Now for some reason it is working on the local computer but when I try to do it from SCCM it just says failed to update. ...
  • Anonymous
    February 04, 2015
    Nice Script, but there is a dangerous flaw that should be fixed!
    If it can't find the "AppstoUninstall.txt" File it will uninstall ALL programs!
  • Anonymous
    February 10, 2015
    This script is EXTREMELY DANGEROUS. As Nozuka says, running this script without the AppstoUninstall.txt file attempts to uninstall every program on the computer.
  • Anonymous
    February 17, 2015
    Hi Justin thanks for really nice script but i have one more script for same purpose but it won't work via SCCM and it works when i run this locally. not sure what wrong i am doing can u please help me in that script how to deploy that script via SCCM.
  • Anonymous
    April 01, 2015
    This worked great for me. Unrelated to the script - I created a new application (java 8u40) and deployed to a test machine with u25.. Did not upgrade/replace - both are installed. Anyone else run into this?
  • Anonymous
    April 02, 2015
    Justin> I figured that's what was going on.. I guess your script will work as an uninstaller going forward.
  • Anonymous
    April 08, 2015
    wmic product where "name like '%%Java %%' and not name like '%%Java 8 Update 40%%'" call uninstall /nointeractive
  • Anonymous
    April 14, 2015
    The comment has been removed
  • Anonymous
    April 24, 2015
    Hi Justin. I am trying to follow this guide but am getting lost all over the place as I am quite new to SCCM 2012. Do you by any chance have a more in depth step by step on how you set this all up?

    Thanks,

    Chris
  • Anonymous
    May 11, 2015
    The comment has been removed
  • Anonymous
    May 26, 2015
    Justin, were you able to find the time to update the script to skip empty lines?

    Thanks,

    Tom
  • Anonymous
    June 02, 2015
    I am unable to download the scrip, I get a 404 error - File or directory not found. Can you provide me with a link? thx
  • Anonymous
    June 02, 2015
    The comment has been removed
  • Anonymous
    June 02, 2015
    nm, I was finally able to download it. Thank you
  • Anonymous
    June 18, 2015
    The comment has been removed
  • Anonymous
    February 16, 2016
    Thanks a lot for this great script. Works perfectly and save me a lot of time
  • Anonymous
    May 16, 2016
    I tried to read through the whole article, and it wasn't clear to me.Will this script handle the common problem: Where the registry and the programs show only the highest version (currently 1.8 update 92), but there are several leftover folders (e.g. for update 60, 51, 72...).That is, will this script remove the folder and file remnants from workstations on the network?Thanks!
  • Anonymous
    November 29, 2016
    The comment has been removed
  • Anonymous
    February 08, 2017
    Just wanted to say thanks for this - Super Job!!, both pieces work like a charm...Was originally going to look at my old batch file (with all the versions of java inside) but came upon your site. We have gone to the extreme and decided to get rid of Java completely from our environment, of course running a pilot first!!
  • Anonymous
    December 12, 2017
    Thanks for your sharing!!!I try to deploy this vbs file by Microsoft SCCM, it works out and show succesfull message on SCCM monitor.But the deployed device is nothing happen.Does anyone knows how to do?Thanks!!!
  • Anonymous
    January 09, 2018
    This is impressive!! You can rework this for any application.. Cheers for writing this up it's brilliant.. Thank you
    • Anonymous
      May 02, 2018
      Thanks for the feedback!
  • Anonymous
    April 24, 2018
    The comment has been removed
    • Anonymous
      April 25, 2018
      The AppsToUninstall.txt file looks like this:Java 8 Update 45Java 8 Update 71Java 8 Update 91Java 8 Update 92Java 8 Update 101Java 8 Update 111Java 8 Update 112Java 8 Update 131Java 8 Update 141Java 8 Update 151Java 8 Update 152Java 8 Update 161
      • Anonymous
        April 27, 2018
        I have got this working, not sure why it works now but I added the lines back into the AppsToUninstall.txt file as shown here:Java 6 UpdateJava(TM) 6 UpdateJ2SE Runtime Environment 5Java 8 Update 45Java 8 Update 71Java 8 Update 91Java 8 Update 92Java 8 Update 101Java 8 Update 111Java 8 Update 131Java 8 Update 141Java 8 Update 151Java 8 Update 152Java 8 Update 161