Uninstalling application using wmic command

I created a fixlet to uninstall a software from windows machine the command works from the command line but fails to uninstall the application through the fixlet.

Command line:

wiathidden cmd /C wmic product where “name like ‘%JAVA%’” call uninstall

I read through this page: How to create Fixlet of a command line
Then tried it using %%JAVA%% but that did not help, I’m not planning to use .bat file and like to keep the process within the fixlet only.

thanks

There is a typo, correct that & it should be good to go.

I used below for 7-zip.
waithidden cmd.exe /C wmic product where "name like '%7-Zip%'" call uninstall /nointeractive

2 Likes

Sorry for the typo I misspelled it as I was typing this post but it’s correct in the fixlet. I tried to run you provided but still not working for me through BigFix yet it works from cmd.

thanks

Is this a 32-bit redirection issue?

Do you have action uses wow64 redirection {not x64 of operating system} in your script before you call wmic?

1 Like

Thanks for your suggestion, I initially didn’t have this line in the script. I introduced it to the script but still failed.

I wouldn’t have expected your command to work, since the cmd shell should interpret %JAVA% as an environment variable.

Something you could try would be

action uses wow64 redirection {not x64 of operating system}
waithidden cmd /C wmic product where "name like '%%JAVA%%'" call uninstall

However I’ve not much used the WMIC method for uninstalling applications. Does this run a silent uninstall (no pop-up messages that need to be acknowledged by the user?)

If you run

cmd /C wmic product where "name like '%%JAVA%%'" call uninstall
from the command line, does it work as expected?

Thanks for your input Jason, I’m not sure why it’s not working from bigfix while it works perfectly from the cmd.

Why the doubling of the percent signs? In @trn’s example, he uses single quotes around single percent signs.

My mistake, actually.

My memory of CMD shell handling of a %VARIABLE% appears to be incorrect. I expected it to treat %JAVA% as a variable reference and evaluate it as nothing (or, if %JAVA% was defined in the shell, to whatever the value was).

But it seems the shell does pass it along literally if %JAVA% is not defined as an environment variable.

C:\Temp>echo %JAVA%
%JAVA%

C:\Temp>echo %PROGRAMFILES%
C:\Program Files

@S2S, you should probably try wrapping in a batch file so you can capture the command outputs and error messages to a log file.

action uses wow64 redirection {not x64 of operating system}
delete __appendfile

waithidden cmd /C wmic product where "name like '%JAVA%'" call uninstall

My mistake, actually, I thought the cmd shell would interpret %JAVA% as an empty shell variable, but apparently it does not, assuming %JAVA% is not set as a variable

C:\Temp>echo %JAVA%
%JAVA%

C:\Temp>echo %PROGRAMFILES%
C:\Program Files

Testing on my system, the following actionscript is working as expected to remove Oracle JDK 21:

action uses wow64 redirection {not x64 of operating system}
waithidden cmd /C wmic product where "name like '%JAVA%'" call uninstall

@S2S, if yours is not working, try posting the snippet of the BES Client Log from this action. I’d also suggest building this as a batch file so you can capture any error messages from the shell.

delete __appendfile
appendfile  wmic product where "name like '%%JAVA%%'" call uninstall
delete uninstall.cmd
move __appendfile uninstall.cmd
action uses wow64 redirection {not x64 of operating system}
waithidden cmd.exe /c uninstall.cmd > c:\windows\temp\output.log 2>&1

I’ve also tested that this works to remove Oracle JDK 21, no dialogs are presented to the user, and it generates the c:\windows\temp\output.log file with this content:

C:\BES\Client\__BESData\actionsite>wmic product where "name like '%JAVA%'" call uninstall
Executing (\\WIN11\ROOT\CIMV2:Win32_Product.IdentifyingNumber="{8D4CF14F-F1A6-576C-AE82-5F90CC628632}",Name="Java(TM) SE Development Kit 21 (64-bit)",Version="21.0.0.0")->Uninstall()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 0;
};
1 Like

@JasonWalker The command line:

wmic product where “name like ‘%%SOME_APP%%’” call uninstall

works perfectly from the command line but not when I run it from bigfix fixlet, I does work on some of the installations and successfully uninstall them and leave others untouched unlike the cmd which completely removes all the deployments.

Something different about your app, then. As I said mine worked with 64-bit JDK 21. What Java, what version, what architecture, are you trying to remove?

How about where I illustrated using a batch file to save the output log? What’s in the output?

@JasonWalker the intent is to use the fixlet to uninstall other applications as well such as putty, I think this is an easier and faster example to demonstrate the issue. Try to install multiple versions of putty 0.78 and 0.79 for x86 and x64 on a x64 system so will end up with a total of 4 installations. If you run the uninstallation using wmic from cmd it will remove all 4 from the system, while running the same exact command from bigfix will only remove 0.79 and leave both 0.78 (x86, x64) untouched, I checked the log file when that happened and it logged “No Instance(s) Available.”

cmd:
wmic product where “name like ‘%%putty%%’” call uninstall

fixlet’s Action Script:
delete __appendfile
appendfile wmic product where “name like ‘%%putty%%’” call uninstall
delete uninstall.cmd
move __appendfile uninstall.cmd
action uses wow64 redirection {not x64 of operating system}
waithidden cmd.exe /c uninstall.cmd > c:\windows\temp\output.log 2>&1

Note: I also tried passing %%PuTTY%% to wmic

Putty version 0.78 downloads:
https://www.chiark.greenend.org.uk/~sgtatham/putty/releases/0.78.html
Putty version 0.79 downloads:
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

Does PuTTY install per-user or per-machine? Have you mixed those in the installation?

I created a task to remove all Java installs with wmic.

It’s Action script line is:

wait wmic product where “name like ‘Java%%’” call uninstall /nointeractive

It works for us :slight_smile:

1 Like

@JasonWalker its installed per-machine, yes the installation were mixed.

Check whether you batch / commands work when running in the LocalSystem account (like BESClient does) using psexec