Identify Java software installed.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
d3v
Posts: 3
Joined: 26 Mar 2021 17:52

Identify Java software installed.

#1 Post by d3v » 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

T3RRY
Posts: 139
Joined: 06 May 2020 10:14

Re: Identify Java software installed.

#2 Post by T3RRY » 27 Mar 2021 02:12

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"

d3v
Posts: 3
Joined: 26 Mar 2021 17:52

Re: Identify Java software installed.

#3 Post by d3v » 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" .
Last edited by Squashman on 27 Mar 2021 12:13, edited 1 time in total.
Reason: MOD EDIT: Please use code tags.

Compo
Posts: 537
Joined: 21 Mar 2014 08:50

Re:Identify Java software installed.

#4 Post by Compo » 27 Mar 2021 09:20

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.

d3v
Posts: 3
Joined: 26 Mar 2021 17:52

Re: Identify Java software installed.

#5 Post by d3v » 27 Mar 2021 10:05

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.

Squashman
Expert
Posts: 4280
Joined: 23 Dec 2011 13:59

Re: Identify Java software installed.

#6 Post by Squashman » 27 Mar 2021 12:14

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]

Post Reply