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
Identify Java software installed.
Moderator: DosItHelp
Re: Identify Java software installed.
Wmic returns a trailing carriage return. to resolve this, use a nested for loop to strip it from the output when generating the output.d3v wrote: ↑26 Mar 2021 18:00Hello 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
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.
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.
Reason: MOD EDIT: Please use code tags.
Re:Identify Java software installed.
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.
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.
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.
It is missing the closing single quote.d3v wrote: ↑27 Mar 2021 07:58this 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" .
The syntax from the help file.
Code: Select all
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]