Jump to content


  • 0
Nunzi0

Uninstall .cmd script not running?

Question

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??

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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 

Share this post


Link to post
Share on other sites

  • 0

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)

Share this post


Link to post
Share on other sites

  • 0

 

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

Share this post


Link to post
Share on other sites

  • 0

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}

Share this post


Link to post
Share on other sites

  • 0

 

 

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.

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.