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.
-
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.
}
-
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
-
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"
) -
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()
}
-
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()
}
-
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
-
Or as we call it here Powell-Shell
http://www.adminarsenal.com/admin-arsenal-blog/category/powershell/
Please sign in to leave a comment.
Comments
30 comments