Uninstalling 7-zip?

Comments

30 comments

  • Stephen Valdinger
    If you can wait until Monday, I can assist with this. Powershell can handle the uninstall of this software, I'll just write a wrapper around the uninstall logic to check version.

    I'll also write it in v2.0 so you don't have script compatibility issues.
    0
    Comment actions Permalink
  • Dan Jackson

    Thanks, that would be really helpful!

    0
    Comment actions Permalink
  • Stephen Valdinger

    Just a heads up, I didn't forget about you. I'm working on this now. 

     

    One quick question, are you using Version 9 of PDQ Deploy? Deciding on how I want to do my error handling, and if you are using V9, I'll use the new methods in that version.

    0
    Comment actions Permalink
  • Dan Jackson

    We should be as we have an Enterprise subscription. I'll check now and if we aren't I'll update.

     

    Thanks.

    0
    Comment actions Permalink
  • Bouma, Colby

    Try this:

    wmic product where "name like '7-Zip%%'" call uninstall /nointeractive

    0
    Comment actions Permalink
  • Stephen Valdinger

    That's likely going to throw a 1603 code. I'm stilling working through a few issues to make this happen a bit cleaner and send error info to output.log in Version 9. 

    0
    Comment actions Permalink
  • Stephen Valdinger

    Suspicions were correct: 


    __GENUS : 2
    __CLASS : __PARAMETERS
    __SUPERCLASS :
    __DYNASTY : __PARAMETERS
    __RELPATH :
    __PROPERTY_COUNT : 1
    __DERIVATION : {}
    __SERVER :
    __NAMESPACE :
    __PATH :
    ReturnValue : 1603
    PSComputerName :

     

    7-zip hooks itself into File explorer (right click and there is a 7-zip contextual menu item. 

     

    This uninstall code WILL work, but you have to wrap it around a way to be able to handle it being used by the explorer process. I'm stilling ironing that little detail out.

     

    0
    Comment actions Permalink
  • Stephen Valdinger

    Ok, I think I've got something here! I was wrong about the process thing. This is all you need, since PDQ deploy will run this code in an elevated prompt, this code will work:

    try {

    #This will grab every version of 7-zip on the system
    $version = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match "7-zip"}

    #Killing explorer momentarily will release the process to uninstall

    $version.Uninstall()


    }

    catch {

    $_.Exception

    exit 1234 #you can make the number anything you want, I'm not really that creative.

    }

     

     

     

     

     

    0
    Comment actions Permalink
  • Dan Jackson

    Thanks, I'll try that once I'm finished dealing with the calls I have on at the moment.

    0
    Comment actions Permalink
  • Dan Jackson

    That script failed with the 1234 error code that you put in there. Any suggestions on how to troubleshoot it?

    0
    Comment actions Permalink
  • Stephen Valdinger

    Click on the Step in the failed deployment and grab the contents of output.log and paste them here if you would please.

    0
    Comment actions Permalink
  • Dan Jackson

    "You cannot call a method on a null-valued expression." it says. So I guess it's somehow not finding the 7-zip uninstall entry? I definitely installed it on the test PC, I downloaded it specifically on there for the purpose.

    0
    Comment actions Permalink
  • Stephen Valdinger

    Hmmm. That's pretty interesting. Can we try to run this outside of PDQ Deploy? Test the powershell code directly on the test pc in question. 

    Also on that machine can you run this and post the output:

    $version = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match "7-zip"} 

    $version.Name

     

     

    0
    Comment actions Permalink
  • Stephen Valdinger

    Also note, please right click and run Powershell ISE as administrator when executing code during our testing.

    0
    Comment actions Permalink
  • Stephen Valdinger

    I was able to replicate the null-valued expression error, but for the life of me I don't understand why it happened.

     

    I installed 7-zip 9.20 and 16.00 on my machine, ran the code to get the name of each version, which yielded what I expected. I then changed $version.Name to $version.Uninstall() and got the null-reference error. I re-ran the code a second time, changing nothing, and it worked just fine! I checked and 7-zip is gone from my system, both versions.

    0
    Comment actions Permalink
  • Bouma, Colby

    This seems to work fairly well for me:

    :: 32-bit
    IF EXIST "C:\Program Files (x86)\7-Zip\Uninstall.exe" (
    "C:\Program Files (x86)\7-Zip\Uninstall.exe" /S /V"/qn /norestart"
    )

    :: 64-bit
    IF EXIST "C:\Program Files\7-Zip\Uninstall.exe" (
    "C:\Program Files\7-Zip\Uninstall.exe" /S /V"/qn /norestart"
    )

    0
    Comment actions Permalink
  • Stephen Valdinger

    I'm working with the 64-bit versions of 7-zip. I don't have an uninstall.exe file to work with! That's interesting, and would definitely be much easier. 

    0
    Comment actions Permalink
  • Stephen Valdinger

    Hmm. I just installed the 32-bit installer, and it has the uninstall.exe file. Why is that not in the 64-bit version?!

    0
    Comment actions Permalink
  • Stephen Valdinger

    Ok, So Here's what I've got for this, give it a shot:

     

    If (Test-Path 'C:\Program Files (x86)\7-zip\uninstall.exe'){

    Write-Host "Uninstall.exe found......using"

    Start-Process -FilePath 'C:\program files (x86)\7-zip\uninstall.exe' -ArgumentList '/S', '/V', '/qn' , '/norestart'


    }

    Else{

    Write-Host "Uninstall.exe not present, using WMI method Uninstall()"

    $version = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match "7-zip"}

    $version.Uninstall()

    }

    0
    Comment actions Permalink
  • Dan Jackson

    We're using the 64-bit versions, so I've changed the script from Program Files (x86) to just Program Files. I'll try it now.

    0
    Comment actions Permalink
  • Dan Jackson

    I got a warning in PDQ Deploy saying I should use Write-Output instead of Write-Host so I changed that as well.

    0
    Comment actions Permalink
  • Dan Jackson

    So this is the script I went with in the end:

     

    If ((Test-Path 'C:\Program Files\7-zip\uninstall.exe') -or (Test-Path 'C:\Program Files (x86)\7-zip\uninstall.exe')){

    Write-Output "Uninstall.exe found......using"

    if (Test-Path 'C:\Program Files\7-zip\uninstall.exe') {
    Start-Process -FilePath 'C:\program files\7-zip\uninstall.exe' -ArgumentList '/S', '/V', '/qn' , '/norestart'
    }
    if (Test-Path 'C:\Program Files (x86)\7-zip\uninstall.exe') {
    Start-Process -FilePath 'C:\program files (x86)\7-zip\uninstall.exe' -ArgumentList '/S', '/V', '/qn' , '/norestart'
    }
    }

    Else{

    Write-Output "Uninstall.exe not present, using WMI method Uninstall()"

    $version = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match "7-zip"}

    $version.Uninstall()

    }

    0
    Comment actions Permalink
  • Stephen Valdinger

    I should have mentioned to take the Write-Hosts out. I throw those in when I'm testing code and forgot to pull them out when I pasted it here. Sorry about that!

     

    Glad that is all working for you now.

    0
    Comment actions Permalink
  • Jason Hanks

    Hey guys.  If scripting isn't your strong suit and you just want to close your eyes and click a button we've got a package published to do this as well in our Enterprise Package Library.

    http://support.adminarsenal.com/entries/99282608-Uninstall-7-Zip-1-0

    0
    Comment actions Permalink
  • Stephen Valdinger

    Forever powershell! :)

    0
    Comment actions Permalink
  • Jason Hanks

    Or as we call it here Powell-Shell

    http://www.adminarsenal.com/admin-arsenal-blog/category/powershell/

    kris.png

    0
    Comment actions Permalink
  • Dan Jackson

    Doh! I didn't think to look in the package library...

    0
    Comment actions Permalink
  • Dan Jackson

    Does the one in the package library fix the default Windows zip association as well? As the 7-zip uninstaller doesn't seem to restore this.

    0
    Comment actions Permalink
  • Stephen Valdinger

    It does not, it strictly uninstalls. If you import the package into your library, you will be able to add a step to the end of that to do that.

     

    You could add a powershell step at the end containing this:

     

    cmd /c assoc .zip=CompressedFolder

    0
    Comment actions Permalink

Please sign in to leave a comment.