Uninstalling 7-zip?
We have a need to remove 7-zip from all the computers in our organisation it is currently installed on. It does not respect the "NoDrives" or "NoViewOnDrive" group policy settings, has no plans to update to support those (https://sourceforge.net/p/sevenzip/feature-requests/545/?limit=25) and also now has a major security vulnerability.
We did look for alternatives but the free ones that we found also shared the same issue, and after reviewing the situation we found that very few users needed to open any archives that weren't .zip files, which are natively supported by Windows.
However, we have a mixture of different versions of 7-zip, not all of which will have the same uninstall method. We have mostly 9.20 but there will be some 15.x versions as well.
Is there a universal uninstaller for this program like there is for things such as Java or Flash? Or, could a script or batch file be created to cope with the different possibilities?
Thanks,
Dan Jackson (Lead ITServices Technician)
Long Road Sixth Form College
Cambridge, UK.
Comments
I'll also write it in v2.0 so you don't have script compatibility issues.
Thanks, that would be really helpful!
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.
We should be as we have an Enterprise subscription. I'll check now and if we aren't I'll update.
Thanks.
Try this:
wmic product where "name like '7-Zip%%'" call uninstall /nointeractive
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.
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.
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.
}
Thanks, I'll try that once I'm finished dealing with the calls I have on at the moment.
That script failed with the 1234 error code that you put in there. Any suggestions on how to troubleshoot it?
Click on the Step in the failed deployment and grab the contents of output.log and paste them here if you would please.
"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.
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
Also note, please right click and run Powershell ISE as administrator when executing code during our testing.
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.
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"
)
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.
Hmm. I just installed the 32-bit installer, and it has the uninstall.exe file. Why is that not in the 64-bit version?!
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()
}
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.
I got a warning in PDQ Deploy saying I should use Write-Output instead of Write-Host so I changed that as well.
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()
}
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.
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
Forever powershell! :)
Or as we call it here Powell-Shell
http://www.adminarsenal.com/admin-arsenal-blog/category/powershell/
Doh! I didn't think to look in the package library...
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.
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
See here:
https://technet.microsoft.com/en-us/magazine/ff687021.aspx
And here:
http://www.bitser.org/restore-zip-file-association-to-windows-default.shtm