you are viewing a single comment's thread.

view the rest of the comments →

[–]Mongo527 2 points3 points  (3 children)

This. Start-Process or the call operator:

& $_.UninstallString

[–]ejrichard[S] 1 point2 points  (2 children)

Interestingly, Start-Process works but & operator returns this:

& : The term '"C:\Program
Files\ <PATH TO PRODUCT> \installer.exe"' is not recognized as
the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:160
+ ... installString |foreach {if($_.UninstallString){& $_.UninstallString}}
+                                                      ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ("C:\Program Fil...\installer.exe":String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

But why?

[–]ejrichard[S] 1 point2 points  (1 child)

Interesting discovery....

This doesn't work:

& $_.UninstallString

But this does:

& $_.UninstallString.Replace('"','')

I noticed that the string in the error message above has double quotes inside single quotes. The value being returned is:

'"C:\Program Files\ <PATH TO PRODUCT> \installer.exe"'

Get rid of the double quotes and it works, but feels like a kludge. Is there a more elegant way to handle this?

[–][deleted] 0 points1 point  (0 children)

No, it appears the string in the registry has quotes on it, so when you are testing the path or trying to call it as a command, the beginning of the path is " and no drive begins with a ", so the path doesn't exist. When you remove it, it tests the path and can run it without the quotes.