[wpkg-users] Removing old Java versions & WMI/registry tricks [was Use regex to get installed version number?]

Will Aoki waoki at umnh.utah.edu
Fri Apr 10 02:20:55 CEST 2015

On Wed, Mar 18, 2015 at 09:26:16AM +0000, Dave Evans wrote:
>         <install cmd='wmic product where "Name like
> 'Java%'" call uninstall /nointeractive' >
>             <exit code='any' />
>         </install>

I've been working on getting Java 8 deployed in my environment, and I
came up with something similar in PowerShell that I thought I'd share.
It doesn't suffer the problems of the WMI Win32_Product class [1], and
it's working in my testing so far.

I haven't integrated into the package yet, but I plan to do it tomorrow.
Until then, here's what I'm doing:

# 32-bit Java on 64-bit Windows
foreach ($i in get-itemproperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
   where-object {$_.displayname -like "Java 8*" } |
   where-object {$_.displayname -notlike "Java 8 Update $shortupdatever*"}) {
  cmd /c ($i.uninstallstring.tostring() + " /qn")
# all platforms
foreach ($i in get-itemproperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
   where-object {$_.displayname -like "Java 8*" } |
   where-object {$_.displayname -notlike "Java 8 Update $shortupdatever*"}) {
  cmd /c ($i.uninstallstring.tostring() + " /qn")

This removes all versions of Java 8 except %shortupdatever%, no need to
keep updating %prevshortupdatever% as the package currently on the wiki
does and no risk of missing uninstalling a version if a machine's left
off for a long time.

Note that this could fail on downgrades if e.g. you're going from update
123 to update 12.

At the moment it doesn't get error codes back to wpkg if an uninstall
fails; that said, I'm probably going to check for <exit code="any" />
and integrate a brute-force uninstall the way I was doing with Java 6.

[1] See <https://support.microsoft.com/en-us/kb/974524> and

More information about the wpkg-users mailing list