Jump to content

Trying to test a modern way of uninstalling


Chimaera
 Share

Recommended Posts

Having trouble with modern installshield uninstallers as they seemed to have changed stuff, so i was trying to make a basic uninstaller to test my theory that it may need PS to do the uninstall

$uninstall = (Get-WmiObject Win32_Product | Where Name -eq "*PowerDirector*").uninstall()

Im using the above but it gives this error

PS C:\windows\system32> $uninstall = (Get-WmiObject Win32_Product | Where Name -eq "*PowerDirector*").uninstall()
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $uninstall = (Get-WmiObject Win32_Product | Where Name -eq "*PowerDirector*").un ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

PS C:\windows\system32>

I thought i had sorted the null by adding 

$uninstall =

Some help please

Link to comment
Share on other sites

This part is null:

(Get-WmiObject Win32_Product | Where Name -eq "*PowerDirector*")

So the call to the uninstall method will not work. It's like trying to do this:

($null).uninstall()

So PowerShell is telling you, it is literally impossible to call a member function of something that is not. It doesn't even get to the variable assignment part because evaluating the expression on the right hand side failed, so what value should it put?

I think the reason it's not "clicking" for you is because it is all written on a single line and you're used to AutoIt where everything is written out on many lines. So you're confused about the order in which it is run. Try writing the same thing as you would write it in AutoIt.

Link to comment
Share on other sites

PS <> WQL, that is the biggest mental hurdle i see ( often directly in my own path :) ).  You can pull it off with -Filter but where-object keeps the queries where they should be.

run("powershell /NoExit Get-WmiObject -class Win32_Product | Where-Object {$_.Name -like '*PowerDirector*'}")

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Thx guys its really to test a theory about modern installshield as they have changed stuff

Ive seen around the web that calling wmi from powershell is the worst way to do things? is this correct?

All im trying to do is uninstall a product from the machine as simply as possible

Link to comment
Share on other sites

The only thing ever 'happening' is msiexec /x.   How you get the system to that point will not be a contest of best -v- worst, it will be an inane race to shave milliseconds.

 However, there are systems that do not have powershell and likewise systems that do not have WMI.  So if you are unleashing it into the wild, it may not be the most all-encompassing of solutions.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • Moderators

I agree with boththose (although more on the lack of powershell on a machine than WMI). When I uninstall through WMI I always do a check. You could theoretically branch off from that point; if you can't make the WMI connection try another method:

$sName = InputBox("Uninstall Wizard", "Please type the first few letters of the application name to search")
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")

    If IsObj($oWMI) Then
        $aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%" & $sName & "%'")
        For $app in $aProducts
            $app.Uninstall()
        Next
    Else
        ;Alternate method Branch - walk through Registry or try PS
    EndIf

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...