HOW TO: Uninstall Program by Name Only
Okay guys, here's something I've been working on. The idea is to pass the below script the name of a program, the script finds the uninstall string and removes it. My idea was this could be used on toolbars, stuff like itunes, etc. Your not gonna want to create a script or distribution for every version (i've done this in the past). Here you would just give it the name of the program you want gone, and if it knows how to uninstall it, it will.
Curerntly supported uninstall strings:
Here's the uninstall script. I wrote it in powershell. Save it as "uninstallScript.ps1" :
From there you can create a new shell script and upload the ps1 as a dependency. Here's what i have for script text. This example uninstalls all versions of Java. You could try your software there.
Remember to change the script name (at the bottom) from script.sh to script.bat.
Hopefully this helps somebody.
Curerntly supported uninstall strings:
- Msiexec commands - These are pretty easy
- Stuff that ends in uninstall.exe - These are usually /S.
- Stuff that ends in helper.exe - These are usually /S
Here's the uninstall script. I wrote it in powershell. Save it as "uninstallScript.ps1" :
###########################################
######## Written by DC 2012-02-13#########
###########################################
<#
.SYNOPSIS
Uninstalls software by only passing the Software Title.
Should work with all msiexec string uninstallers.
For uninstall commands that end in uninstall.exe or helper.exe a "/S" is used as a switch.
.PARAMETER DisplayName
The complete or partial name of the software being uninstalled. Must appear as shown in add / remove programs (case insenstive).
.EXAMPLE
Uninstall-Program Java
Will search the registry and uninstall all instances of Java from a machine.
#>
[cmdletBinding()]
Param
(
[String]$DisplayName = $(throw "DisplayName is Required")
)
Set-Variable -Name ThirtyMachine -Value "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -Option Constant
Set-Variable -Name SixtyMachine -Value "HKLM:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall" -Option Constant
Set-Variable -Name ThirtyUser -Value "HKCU:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall" -Option Constant
Set-Variable -Name SixtyUser -Value "HKCU:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall" -Option Constant
$regs = $ThirtyMachine,$SixtyMachine,$ThirtyUser,$SixtyUser
foreach ($reg in $regs)
{
if(Test-Path $reg)
{
$SubKeys = Get-ItemProperty "$reg\*"
}
else
{
$SubKeys = $null
}
foreach($key in $SubKeys)
{
if($key.DisplayName -match "$DisplayName")
{
Write-Host "Found Software " $key.DisplayName
if($key.UninstallString -match "^msiexec")
{
$startGUID = $key.UninstallString.IndexOf("{") + 1
$endGuid = $key.UninstallString.IndexOf("}") - $startGUID
$stringer = $key.UninstallString.Substring($startGUID,$endGuid)
Write-Host "Uninstaller Known, now uninstalling"
&msiexec `/qn `/x `{$stringer`}
}
if($key.UninstallString.Replace('"',"") -match 'uninstall.exe\Z' -or $key.UninstallString.replace('"',"") -match 'helper.exe\Z' )
{
$stringer = $key.UninstallString.Replace('"',"")
if(Test-Path $stringer )
{
Write-Host "Possible Uninstaller found. Trying" $key.UninstallString "/S"
&$stringer /S
}
}
}
}
}
From there you can create a new shell script and upload the ps1 as a dependency. Here's what i have for script text. This example uninstalls all versions of Java. You could try your software there.
powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "uninstallScript.ps1" "Java"
Remember to change the script name (at the bottom) from script.sh to script.bat.
Hopefully this helps somebody.
0 Comments
[ + ] Show comments
Answers (0)
Please log in to answer
Be the first to answer this question
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.