JAVA Uninstall (multiple versions)

Hello again everyone -

I’m looking for a working fixlet that would remove any version of JAVA runtime (or, for now, any version for JAVA 8, not for JAVA 11, though that would be needed later I think).

I’ve seen multiple threads on this, and saw where someone was asking for the same thing (Uninstalling ALL Versions of JAVA) which had a referenced to “attached fixlets”, but I’m not seeing any attachments to that post.

{ removed old text here… }

Replicating what I have here to see if I can get this nailed down better.

In my case I want to create a .bat file that I can call that will run the msiexec commands as needed (completely bypassing the Powershell script signing issue).

// modify the version number in the next line to affect all versions of JAVA except that version
IF{exists keys whose (value "DisplayName" of it as string as lowercase contains "java" AND (value "Publisher" of it as string as lowercase contains "oracle" OR value "Publisher" of it as string as lowercase contains "sun") AND value "DisplayName" of it as string as lowercase does not contain "java auto updater" AND value "DisplayName" of it as string as lowercase does not contain "java 8 update 199") of keys "hklm\software\microsoft\windows\currentversion\uninstall" of (native registry;registry)}
// note: this may also remove JAVA SE Development Kit.  Need to confirm that before applying on any system with the JDK installed
// note also: version number was set to 199 above.  There are currently no versions of JAVA Runtime at that level, so this should catch all installed versions at -location redacted- (within -org redacted-)

delete __appendfile

appendfile {concatenation "%0d%0a" of (name of it) of keys whose (value "DisplayName" of it as string as lowercase contains "java" AND (value "Publisher" of it as string as lowercase contains "oracle" OR value "Publisher" of it as string as lowercase contains "sun") AND value "DisplayName" of it as string as lowercase does not contain "java auto updater" AND value "DisplayName" of it as string as lowercase does not contain "java 8 update 199") of keys "hklm\software\microsoft\windows\currentversion\uninstall" of (native registry;registry)}

delete c:\windows\temp\javaUninstall.txt
copy __appendfile c:\windows\temp\javaUninstall.txt
// copy the javaUninstall.txt file to the server logs folder
copy __appendfile \\server\logs\{Computer name}_javaUninstall.txt

endif

delete __createfile

createfile until EOF
for /F %%A in ("c:\windows\temp\javaUninstall.txt") do @echo "msiexec.exe -ArgumentList /x %%A /qn REBOOT=ReallySuppress -wait -passthru" >> "c:\windows\temp\JavaUninstall.bat"

EOF

delete c:\windows\temp\javaUninstall-loop.bat
delete c:\windows\temp\javaUninstall.bat
copy __createfile c:\windows\temp\javaUninstall-loop.bat
copy __createfile \\server\logs\{Computer name}_javaUninstall.bat

 runhidden cmd /K c:\windows\temp\javaUninstall.bat

I was expecting and hoping that I had this worked out at this point, but seemingly I don’t :frowning:

I tried to run the script and it failed in the code, somewhere after it created the text file for me. (It would appear to have failed at the point that the file for the JavaUninstall-Loop.bat file should be getting created, in the createfile until EOF area

I’m gonna work on some more troubleshooting to see if I can figure this out, but appreciate suggestions and input.

I’m pretty sure that when you use ‘echo’ in this way, the doublequotes would literally be included. So the output file would be

"msiexec.exe -ArgumentList /x GUID-1 /qn REBOOT=ReallySuppress -wait -passthru" 
"msiexec.exe -ArgumentList /x GUID-2 /qn REBOOT=ReallySuppress -wait -passthru" 

…and the comands would fail. Try it without the quotes. Or better yet, put the uninstall commands in the relevance output directly

q: concatenation "%0d%0a" of ("start /wait %22%22 msiexec.exe /x" & name of it & " /qn REBOOT=ReallySuppress" ) of keys whose (value "DisplayName" of it as string as lowercase contains "java" AND (value "Publisher" of it as string as lowercase contains "oracle" OR value "Publisher" of it as string as lowercase contains "sun") AND value "DisplayName" of it as string as lowercase does not contain "java auto updater" AND value "DisplayName" of it as string as lowercase does not contain "java 8 update 199") of keys "hklm\software\microsoft\windows\currentversion\uninstall" of (native registry;registry)
A: start /wait "" msiexec.exe /x{26A24AE4-039D-4CA4-87B4-2F64180192F0} /qn REBOOT=ReallySuppress%0d%0astart /wait "" msiexec.exe /x{64A3A4F4-B792-11D6-A78A-00B0D0180920} /qn REBOOT=ReallySuppress%0d%0astart /wait "" msiexec.exe /x{26A24AE4-039D-4CA4-87B4-2F32180192F0} /qn REBOOT=ReallySuppress
1 Like

Thanks Jason - taking a look at your suggestions now. I had thought about trying to work that out, but was a little confused at the concatenation area. (I had assumed that I could get the string I needed out in a single line and not need to go through the second loop and such)

So following the logic, if your suggestion works (and I would expect it would), then I simply create the appendfile which can be copied to the .bat file that can then be run on the system.

Yes, that’s what I’d expect -

delete __appendfile

appendfile {concatenation "%0d%0a" of ("start /wait %22%22 msiexec.exe /x" & name of it & " /qn REBOOT=ReallySuppress" ) of keys whose (value "DisplayName" of it as string as lowercase contains "java" AND (value "Publisher" of it as string as lowercase contains "oracle" OR value "Publisher" of it as string as lowercase contains "sun") AND value "DisplayName" of it as string as lowercase does not contain "java auto updater" AND value "DisplayName" of it as string as lowercase does not contain "java 8 update 199") of keys "hklm\software\microsoft\windows\currentversion\uninstall" of (native registry;registry)}

delete RemoveJava.bat
move __appendfile RemoveJava.bat
waithidden cmd.exe /c RemoveJava.bat
2 Likes

Thanks again very, very much! Definitely much cleaner and easier and again avoids the issue that I was having with Powershell script signing requirements.

I’d also point out that the three out-of-the-box fixlets for cleaning up Java are working pretty well for me -

7057003	Java Runtime Environment - Multiple 32-bit JRE Versions Installed - J2SE 1.4.2 and Up (x64)		

7057001	Java Runtime Environment - Multiple 64-bit JRE Versions Installed - J2SE 1.4.2 and Up (x64)		

7052001	Java Runtime Environment - Multiple JRE Versions Installed - J2SE 1.4.2 and Up		

These are in the “Updates for Windows Applications” site. There is a difference though - yours removes “everything below version X”, while the default ones remove “all except the highest currently-installed version”

3 Likes

Glad I was able to help

1 Like

Thanks for pointing that out too, though unfortunately for us, I’ve gotta remove all instances and not leave even the most recent. Or will have to do that soon (currently in testing for this, not yet with the hard requirement to remove, but it is coming very soon now).

As of End-of-Life of JAVA 8, we’ll be getting rid of JAVA (the Oracle “paid” supported versions). Going with OpenJDK in the places where we’d need to have it available (fewer, and more far between than the current presence where we have many installs of the JRE because it used to be “free” and could be used without worry about costs, etc.)

Oracle of course wants to be paid and their new model of releases every 6 months give or take will be much more hassle for the folks I work for and the frequency with which we are really able to upgrade and replace stuff like this. OpenJDK will have more of a Long Term Support option and that works better for us.

Ooops, apologies @JasonWalker had to take back the solution mark for a few minutes… close, but…

What I’m getting now is still not quite there, but lets see what the script now looks like to make it cleaner…

 delete __appendfile

appendfile concatenation "%0d%0a" of ("start /wait %22%22 msiexec.exe /x" & name of it & " /qn REBOOT=ReallySuppress" ) of keys whose (value "DisplayName" of it as string as lowercase contains "java" AND (value "Publisher" of it as string as lowercase contains "oracle" OR value "Publisher" of it as string as lowercase contains "sun") AND value "DisplayName" of it as string as lowercase does not contain "java auto updater" AND value "DisplayName" of it as string as lowercase does not contain "java 8 update 199") of keys "hklm\software\microsoft\windows\currentversion\uninstall" of (native registry;registry)

delete c:\windows\temp\javaUninstall.bat
copy __appendfile c:\windows\temp\javaUninstall.bat
// copy the javaUninstall.bat file to the server logs folder
copy __appendfile \\server\logs\{Computer name}_javaUninstall.bat

endif

runhidden cmd /K c:\windows\temp\javaUninstall.bat

That is creating a file that actually contains the text of the concatenation.

Ooops again, I missed the { } that were wrapped into your solution. Solution marked again :smile:

Looks like I needed one more subtle change, but this was easier…

appendfile {concatenation "%0d%0a" of ("start /wait %22msiexec.exe /x" & name of it & " /qn REBOOT=ReallySuppress%22" ) of keys whose (value "DisplayName" of it as string as lowercase contains "java" AND (value "Publisher" of it as string as lowercase contains "oracle" OR value "Publisher" of it as string as lowercase contains "sun") AND value "DisplayName" of it as string as lowercase does not contain "java auto updater" AND value "DisplayName" of it as string as lowercase does not contain "java 8 update 199") of keys "hklm\software\microsoft\windows\currentversion\uninstall" of (native registry;registry)}

Moved the second of the %22 (the " marks) to the end of the string that is being output and appended in the file.

What I got originally was an entry that looked like this:

start /wait "" msiexec .....

What I should have:

start /wait "msiexec ...."

Actually start /wait "" msiexec... was intended. It’s kind of a failsafe I always do with the ‘start’ command.

The ‘start’ command assumes the first quoted thing should be the title of the new window it spawns. Doesn’t matter if those quotes are at the beginning, middle, or end of the command line. So I always include an empty set of doublequotes so the window is created without a title, and no following set of quotes is misinterpreted as a title.

You might also encounter a problem using cmd /K rather than cmd /C. The ‘/K’ keeps the command shell open after the batch script is finished, so your action might not end. The ‘/C’ parameter closes the shell when the batch completes, so the ‘waithidden’ can see that it’s finished.

1 Like

Thanks again, that makes sense and explains what I was seeing a bit ago in my testing. (Bringing back my memories of DOS scripting and such).

i’m getting the command as the title now as you would have expected. Fix that momentarily and test some more. Close, so close…

Changed to this now:

appendfile {concatenation "%0d%0a" of ("start /wait %22JRE Uninstall%22 msiexec.exe /x"

and used the /C instead of the /K

manual testing of the .bat file worked with that approach… hopefully it’ll do the same thing again as I reload and test again on the same device that I’ve been testing on.

I must admit I want to :cry: a little in not remembering more of the DOS (.bat) and CMD file processing that I used to know so well. My skills have gotten so rusty in that area from not being able to use them as much as I used to. Too much bouncing around between different functions at work and not enough time doing dedicated scripting. :wink:

Back one last time to note that the script worked and passed testing. Still probably test on a few more devices before trying to use it on the majority of the systems where it would be applicable, but I definitely feel more comfortable that we should be ready for the bulk removal that is now pending for us.

Thanks again Jason for all of the help. Definitely appreciated. (Sometime, somewhere, hopefully we’ll meet and I’ll get to buy you a beer or other beverage of your choosing!)

1 Like

can you provide the final iteration of the entire file?