/build/static/layout/Breadcrumb_cap_w.png

Conditional Uninstall

HELP! [:o] Being really new to the scripting world, I've been racking my brain on how to write a vbscript that would check for the existance of an application in the registry. If the application exists, then have it run the UNINSTALL STRING that is associated with the app. I've got the script to atleast echo the results of what is installed, but cannot seem to get it to kick of the UNINSTALL STRING. Basically I need the script to check for an app (from within the registry) then uninstall the cotton-pickin' thing! LOL! [8|] ANY help would be greatly appreciated!!!! Thanks a million scripting pals! Have a good one!

0 Comments   [ + ] Show comments

Answers (5)

Posted by: brenthunter2005 19 years ago
Fifth Degree Brown Belt
0
Hello strakm,

How do you query the registry for the list of installed applications?

If you use WMI to query the installed applications on a computer, you can also uninstall the application this way.
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
For an MSI based installation, this might work:

Const sPARTIALPRODNAME = "Partial App Name"

Const msiINSTALLSTATEABSENT = 2

Set oInstaller = Wscript.CreateObject("WindowsInstaller.Installer")

Set oProducts = oInstaller.Products

For Each sProdCode in oProducts

sProdName = oInstaller.ProductInfo(sProdCode, "ProductName")

iFindPos = Instr(LCase(sProdName), LCase(sPARTIALPRODNAME))

If iFindPos <> 0 Then oInstaller.ConfigureProduct sProdCode, 0, msiINSTALLSTATEABSENT : Exit For

Next

Set oProducts = Nothing
Set oInstaller = Nothing
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
Here's an old script I found on my hard drive - I think it does what you're looking to do? It probably needs tidying up a bit, and it won't look to pretty once I've posted it because the indentation will be lost!


Dim oWsh : Set oWsh = CreateObject("Wscript.Shell")

UninstallProduct "Some Application"

'**********************************************************************************

Sub UninstallProduct(sPartDisplayName)
On Error Resume Next

Dim oKeys, i, sDispName, sUninstall

Const sTOPKEY = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"

oKeys = EnumKeys(sTOPKEY, True)

For i = 0 to Ubound(oKeys)

sDispName = LCase(oWsh.RegRead(sTOPKEY & "\" & oKeys(i) & "\DisplayName"))

If Instr(sDispName, LCase(sPartDisplayName)) <> 0 Then

sUninstall = oWsh.RegRead(sTOPKEY & "\" & oKeys(i) & "\UninstallString")

If sUninstall <> "" Then oWsh.Run sUninstall, 5, True : Exit Sub

End If

Next

End Sub

'**********************************************************************************

Function EnumKeys(Path, bSubKeys)

Dim oOutParam, oRegistry, oMethod, oInParam, sRoot, iRoot, i, oNames,sPath

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005

sRoot = Left(Path, Instr(Path,"\")-1)

sPath = Mid(Path, Instr(Path,"\")+1)

Select Case sRoot

Case "HKCR"

iRoot = HKEY_CLASSES_ROOT

Case "HKCU"

iRoot = HKEY_CURRENT_USER

Case "HKEY_CURRENT_USER"

iRoot = HKEY_CURRENT_USER

Case "HKEY_CLASSES_ROOT"

iRoot = HKEY_CLASSES_ROOT

Case ELSE

iRoot = HKEY_LOCAL_MACHINE

End Select

Set oRegistry = GetObject("winmgmts:/root/default:StdRegProv")

Set oMethod = oRegistry.Methods_("EnumValues")
Set oInParam = oMethod.inParameters.SpawnInstance_()

oInParam.hDefKey = iRoot
oInParam.sSubKeyName = sPath

If Not bSubKeys Then

Set oOutParam = oRegistry.ExecMethod_("EnumValues", oInParam)

Else

Set oOutParam = oRegistry.ExecMethod_("EnumKey", oInParam)

End If

Set oNames = oOutParam.Properties_("sNames")

Dim oSubKeys() : ReDim oSubKeys(-1) ' -1 signifies an valid but empty array.

If Not IsNull(oNames) then

Redim oSubKeys(UBound(oOutParam.Properties_("sNames")))

For i=0 To UBound(oOutParam.Properties_("sNames"))

oSubKeys(i) = oOutParam.Properties_("sNames")(i)

Next

End If

EnumKeys = oSubKeys

End Function
Posted by: bkelly 19 years ago
Red Belt
0
Also check out the Admin Script Editor "Uninstall Wizard" - http://www.adminscripteditor.com/wizards/view.asp?id=21

It looks at your system and provides uninstall scripts in the language of your choice based on those applications that support a silent uninstall. It requires that you install the Admin Script Editor, but it does work with the free trail: http://www.adminscripteditor.com/editor
Posted by: strakm 19 years ago
Senior Yellow Belt
0
Great! Thanks for the replies Gentlemen!!! Brenthunter2005, I am enumerating the keys. Thanks again Everyone!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ