Skip to content

Uninstall .cmd script not running?

Featured Replies

I've deployed a .cmd file out that contains a WMI script to uninstall all instances of an application called "VirtViewer". The script looks like this:

taskkill /F /IM remote-viewer.exe /T

wmic product where "name like 'VirtViewer%%'" call uninstall /nointeractive


exit /B %EXIT_CODE%

Previously, I had used MSI product codes for the uninstall, and got the same result. My original problem, is that there are currently 9 different versions of this app out there, so i am ripping them all out and replacing with 1 version. Installing over an old version does not overwrite the older one, it instead installs a new instance.

 

Reading through the execmgr.log on the client, everything looks as it should. I have attached the execmgr.log to the post.

 

 

The end result, is that nothing happens. I had originally set the program to run as hidden, but then changed it to normal but still do not see it run. The application is right where i left it, untouched. If i run the script locally it works fine, but not when deployed. Am i missing something??

  • Author

I would start by testing the "script" via PSEXEC to run the "script" with SYSTEM credentials like ConfigMgr does.

 

I did end up trying this from a post on another forum. I used psexec -s -i cmd.exe and did a whoami to verify i was logged in as nt authority/system. The script ran fine when used that way. However, i added logging to the original .cmd file like this:

 

New Script:

taskkill /F /IM remote-viewer.exe /T

echo start >"C:\temp\virtviewer.log"

wmic product where "name like 'VirtViewer%%'" call uninstall /nointeractive >>"C:\temp\virtviewer.log"

echo done >>"C:\temp\virtviewer.log"

exit /B %EXIT_CODE%

When deploying the script through ConfigMgr i get this from the log file:

start 
No Instance(s) Available.
done 

When running the exact same script locally i get:

start 
Executing (\\VM-WIN7-MIKE\ROOT\CIMV2:Win32_Product.IdentifyingNumber="{235D4E1F-1C6F-4F75-BE85-A3B652AD3315}",Name="VirtViewer 0.5.6-25.el6_5.3.4.1 (64-bit)",Version="0.5.1561")->Uninstall()

Method execution successful.

Out Parameters:
instance of __PARAMETERS
{
	ReturnValue = 0;
};
done 

You should avoid to access the Win32_Product class. Each time you access the class all installed products will be evaluated again, including the sources in c:\windows\installer. This eats a lot of I/O and time.

$ExitCode = 0
gwmi -Namespace root\cimv2\SMS -Class SMS_installedSoftware -Filter "ProductName Like 'VirtViewer%'" -Property SoftwareCode,ProductName | % { 
    $myArgs = "/X" + $_.SoftwareCode + " /norestart /q"
    $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $myArgs -ErrorAction SilentlyContinue -NoNewWindow -Wait -PassThru).ExitCode
}
[Environment]::Exit($ExitCode)
  • Author

 

You should avoid to access the Win32_Product class. Each time you access the class all installed products will be evaluated again, including the sources in c:\windows\installer. This eats a lot of I/O and time.

$ExitCode = 0
gwmi -Namespace root\cimv2\SMS -Class SMS_installedSoftware -Filter "ProductName Like 'VirtViewer%'" -Property SoftwareCode,ProductName | % { 
    $myArgs = "/X" + $_.SoftwareCode + " /norestart /q"
    $ExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList $myArgs -ErrorAction SilentlyContinue -NoNewWindow -Wait -PassThru).ExitCode
}
[Environment]::Exit($ExitCode)

 

I'm getting an error trying to run this. UnauthorizedAccessException

gwmi : 
At line:2 char:1
+ gwmi -Namespace root\cimv2\SMS -Class SMS_InstalledSoftware -Filter "ProductName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ( [Get-WmiObject], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
  • Author

I ended up resolving my issue. I set the program to run "Only when a user is logged on" and it worked perfectly. This p[articular program must be on a per user basis, uninstalling from SYSTEM was not working properly. I kept getting No Instances available, or 1605 errors when trying to uninstall from system, even with msiexec /x {product code}

 

 

I'm getting an error trying to run this. UnauthorizedAccessException

gwmi : 
At line:2 char:1
+ gwmi -Namespace root\cimv2\SMS -Class SMS_InstalledSoftware -Filter "ProductName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ( [Get-WmiObject], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

 

You should only get this error when try to run the script in the user context. I f you get the error in the system context you should be worried about the DCOM permissions on your machine.

 

 

Since you can uninstall the program in the user context it got originally installed in this context for whatever reason.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.