Page 1 of 1

Identify Java software installed.

Posted: 26 Mar 2021 18:00
by d3v
Hello all - I hope someone can help me code this...

objective is to identify all JAVA software installed so I can uninstall them from a host (using script)

i have a text file output which i am generating in cmd prompt (bat file)

wmic product get description | findstr /i java >remove_java.cmd

problem is the output file remove_java.cmd - it generates the file with trailing spaces in the output for each name it picks up
for example:

Java 8 Update
Java 8 Update 281 (64-bit)
Java SE Development Kit 8 Update 281 (64-bit)

all above three lines have trailing white spaces which I would like to remove.

what command can I use.

and as an addition I would like to update the line to following - so I can use it to remove the installs via command line.

WMIC Product Where "description='Java 8 Update 281'" Uninstall
WMIC Product Where "description='Java 8 Update 281 (64-bit)'" Uninstall
WMIC Product Where "description='Java SE Development Kit 8 Update 281 (64-bit)" Uninstall

Re: Identify Java software installed.

Posted: 27 Mar 2021 02:12
by T3RRY
d3v wrote:
26 Mar 2021 18:00
Hello all - I hope someone can help me code this...

objective is to identify all JAVA software installed so I can uninstall them from a host (using script)

i have a text file output which i am generating in cmd prompt (bat file)

wmic product get description | findstr /i java >remove_java.cmd

problem is the output file remove_java.cmd - it generates the file with trailing spaces in the output for each name it picks up
for example:

Java 8 Update
Java 8 Update 281 (64-bit)
Java SE Development Kit 8 Update 281 (64-bit)

all above three lines have trailing white spaces which I would like to remove.

what command can I use.

and as an addition I would like to update the line to following - so I can use it to remove the installs via command line.

WMIC Product Where "description='Java 8 Update 281'" Uninstall
WMIC Product Where "description='Java 8 Update 281 (64-bit)'" Uninstall
WMIC Product Where "description='Java SE Development Kit 8 Update 281 (64-bit)" Uninstall
Wmic returns a trailing carriage return. to resolve this, use a nested for loop to strip it from the output when generating the output.

Code: Select all

 (For /F "Delims=" %%G in ('^
   wmic product get description ^| findstr /lic: "java"^
  )Do For %%O in (%%G)Do Echo(%%O
 ) >"remove_java.cmd"

Re: Identify Java software installed.

Posted: 27 Mar 2021 07:58
by d3v
this did not work - gave error

Code: Select all

 (For /F "Delims=" %%G in ('^
   wmic product get description ^| findstr /lic: "java"^
  )Do For %%O in (%%G)Do Echo(%%O
 ) >"remove_java.cmd"


D:\JV>(For /F "Delims=" %G in ('  wmic product get description | findstr /lic: "java" ) Do For %O in (%G) Do Echo(%O ) 1>"remove_java.cmd"
The system cannot find the file '  wmic product get description | findstr /lic: "java" .

Re:Identify Java software installed.

Posted: 27 Mar 2021 09:20
by Compo
d3v wrote:
26 Mar 2021 18:00
wmic product get description | findstr /i java >remove_java.cmd
Don't do it like that, the official recommendation is not to use Win32_Product, (for which Product is a WMIC alias).

When Win32_Product is enumerated, it actually performs a full status check on each product. This not only affects your script time, on top of that of the already slow WMIC utility, but can also mean that repairs/modifications are made to the enumerated products too.

I would advise that you use the reg.exe utility to enumerate the subkeys of HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products instead. The resulting batch file may be more complex codewise, but it would be safer, and would run much quicker.

Re: Identify Java software installed.

Posted: 27 Mar 2021 10:05
by d3v
agreed with the points laid out...will code accordingly.

in the meantime, found a one line code which uninstalled all JAVA installs in one line - and no coding was required.

wmic product where "name like '%%Java%% Update%%'" call uninstall

tested and it worked perfectly....but will work on develing further using the reg.

thanks all.

Re: Identify Java software installed.

Posted: 27 Mar 2021 12:14
by Squashman
d3v wrote:
27 Mar 2021 07:58
this did not work - gave error

Code: Select all

 (For /F "Delims=" %%G in ('^
   wmic product get description ^| findstr /lic: "java"^
  )Do For %%O in (%%G)Do Echo(%%O
 ) >"remove_java.cmd"


D:\JV>(For /F "Delims=" %G in ('  wmic product get description | findstr /lic: "java" ) Do For %O in (%G) Do Echo(%O ) 1>"remove_java.cmd"
The system cannot find the file '  wmic product get description | findstr /lic: "java" .
It is missing the closing single quote.
The syntax from the help file.

Code: Select all

FOR /F ["options"] %variable IN ('command') DO command [command-parameters]