简体   繁体   中英

How to uninstall a program using a version-independent name in WMIC

I was creating a batch to automate Java uninstallation:

wmic product where name="Java 8 Update 321 (64-bit)" call uninstall /nointeractive

but Oracle renamed app in WMIC as Java 8 Update 321 (64-bit). For example in the future Oracle will release new version 322, my batch will simply stop working due to the different version. It's not only name that Oracle changes every update, it also changes ID like {26A24AE4-039D-4CA4-87B4-2F64180 321 F0}.

I already tried using an alternative using winget like this:

winget install "Oracle.JavaRuntimeEnvironment" works

winget uninstall "Oracle.JavaRuntimeEnvironment" doesn't work because ID is different, which was {26A24AE4-039D-4CA4-87B4-2F64180 321 F0}, which has to do with version number.

Is there a way to uninstall without version number in batch?

for /f "delims=" %%b in ('wmic product get description^|find "Java" ') do set "javaversion=%%b"
echo ready to delete "%javaversion%"

Then wmic product where name="%javaversion%" call un...

(That's just to set an environment variable & display it)

If you're feeling brave, try

for /f "delims=" %%b in ('wmic product get description^|find "Java" ') do ECHO wmic product where name="%%b" call uninstall /nointeractive

and remove the echo keyword to actually perform the uninstall.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM