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)
Please log in to answer
Posted by:
brenthunter2005
19 years ago
Posted by:
WiseUser
19 years ago
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
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
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
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
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
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
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.