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:
- 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.
John - jverbosk 12 years ago
I tried to use this SCript in Windows 7. it worked fine. But When I tried to use it in Windows XP it failed. Any idea? - V_siddhaarth 12 years ago
$app = gwmi win32_product | where-object { $_.name -match "" }
$app.uninstall() - muebel 12 years ago
The reason you change to .bat in the lower section is because the script is actually calling powershell.exe. If you let the "script file name" at .sh it would try and execute a shell script. Changing that line to .bat just makes it available to run on Windows.
Does that make sense? - dugullett 11 years ago
How can I use this script to uninstall all 5 apps which start CSC ?
Any ideas would be very useful. - spadge007 10 years ago
At this line add START /WAIT:
&msiexec `/qn `/x `{$stringer`}
change to
&START /WAIT msiexec `/qn `/x `{$stringer`}
This should allow each uninstall to finish before starting the next. - dugullett 10 years ago
.\uninstallScript.ps1 "CSC"
I get the following error
.\UninstallScript.ps1 "CSC"
Found Software CSC License Service
Uninstaller Known, now uninstalling
Start-Process : A positional parameter cannot be found that accepts argument '/
qn'.
At C:\Users\test\Desktop\PSTest\UninstallScript.ps1:60 char:2
+ & <<<< START /WAIT msiexec `/qn `/x `{$stringer`}
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterB
indingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.StartProcessCommand
I amended line 60 as you suggested to:
&START /WAIT msiexec `/qn `/x `{$stringer`} - spadge007 10 years ago
Uninstall.ps1:60 char:1
+ &msiexec `/qn `/x `{$stringer`}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({{0}}}:String) [], RuntimeExc
eption
+ FullyQualifiedErrorId : FormatError - DaBXRoMeO 7 years ago
Running as System, if i do or do not qualify the path (even added a step before the powershell step copying the file to a common folder) in k1000 it does not work.
Running as my ID, I don't have to qualify the path to the ps1 file but msiexec throws an error in the event log stating that i must be an administrator to run it. My id IS in the local Admins group so I'm guessing this has to do w/ it needing elevation. - adaml 10 years ago
"%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe"
When is the k1000 agent going to be a 64bit application? Criminy! - adaml 10 years ago
Set-Variable -Name SixtyUser -Value "HKCU:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall" -Option Constant
Is seems to me this is incorrect. It should be:
Set-Variable -Name ThirtyUser -Value "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -Option Constant
Set-Variable -Name SixtyUser -Value "HKCU:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall" -Option Constant - anonymous_123154 9 years ago
how do you add a log at the statement? I will like to see a log file created i.e. c:\temp\softwarename_uninstall.log - artifect 8 years ago