I have a software installation script for excecutables. I need to know if the software exist and want to use the uninstall registry folder to see if de display name exist. The script needs to look inside the unninstal folder for a value.

I have found a script that deletes the value. i am having problems converting this to a check if value exist then key exist = True

Const HKU_USERS = &H80000003

 

strComputer = "."

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") 

 

strIPDKeyPath = "\Software\FileNET\IDM\Preferences\Libraries" 

 

DeleteIPDSubkeys HKU_USERS, strIPDKeyPath

 

Sub DeleteIPDSubkeys(HKU_USERS, strIPDKeyPath) 

    objRegistry.EnumKey HKU_USERS,"", arrSubkeys 

 

    If IsArray(arrSubkeys) Then 

        For Each strSubkey In arrSubkeys 

If instr(strSubKey, "AIT") > 0 Then

' Search and Delete Key and sub keys

SearchAndDeleteSubKeys strIPDKeyPath & "\" & subkey

 

objRegistry.DeleteKey HKU_USERS, strIPDKeyPath 

End If

        Next 

    End If 

End Sub

 

sub SearchAndDeleteSubKeys (SubKeyToSearch)

Dim intArraySize

 

objRegistry.EnumKey HKEY_LOCAL_MACHINE, SubKeyToSearch, arrSearchSubKeys

 

intArraySize = UpperBound(arrSearchSubKeys)

 

if intArraySize < 0 then

objRegistry.DeleteKey HKEY_CURRENT_USER,strKeyPath

Else

For Each subkey In arrSearchSubKeys

SearchAndDeleteSubKeys(SubKeyToSearch & "\" & subkey)

Next

End If

End sub

 

Function UpperBound (ArrayToSize)

' Find size of array.  Return -1 if it has not size

Dim intSize

msgbox "Here"

 

On Error Resume Next

intSize = Ubound(ArrayToSize)

On Error Goto 0

 

If len(intSize) > 0 then

' Ubound returned a value.  Use it

UpperBound = intSize

Else

' UBound Errored send back a -1

UpperBound = -1

End if

 

End Function
 

I hope somebody can help me with this. or another way to see if a progam exist when using executables.

Answer Summary:
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

4

You can use this. It is powershell though.

 
$app = gwmi win32_product | where-object { $_.name -match "ENTER NAME OF SOFTWARE" }
$app.uninstall()
 
Answered 06/19/2012 by: dugullett
Red Belt

  • nice!! i only don't know if SCCM can execute power shell files. And this is also for MSI installations
    • I've ran into some instances where I've had to change -match to -like. I'm pretty sure it's been on all of my smaller apps though.

      I would think SCCM can execute Powershell since they are both Microsoft products. If not go here https://www.kace.com/support/trial-kbox/how-to-buy
      • That should make sense. I am trying do remove SAP GUI 7.1. The clients still run windows XP and i am pretty sure they have not powershell installed.
  • SP3 should have it.
  • So you'll know the path everytime, or will this be something random?
    • Its a script for random use. i would like to add only the software name for him to see if it exist. since i already created a vb script for this i would like to continue on that.
Please log in to comment

Answers

2

Just in case anyone needs this. This will check the reg and get uninstall path. In this example "/S" was the silent switch for the uninstall. When WMI will not find it.

Not VB in Powershell.

$APP = Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall | foreach-object {Get-ItemProperty $_.PsPath}

$UninstallString = $APP | ? { $_.displayname -match "NAME OF SOFTWARE" } | select uninstallstring

cmd /c $UninstallString.UninstallString /S
 
Answered 06/19/2012 by: dugullett
Red Belt

Please log in to comment

  • Very nice script... only this is for checking a MSI installation with product key. Executables do not have product keys
  • Well the complete script is for running msi installation/upgrade but it contains a function for finding all products in add/remove program by searching the registry. This functions also finds the uninstallstring which in your case could be used to find the path to the uninstall.exe at least. So if your software is visable in add/remove programs you should be able to use this. Of course you will need to modify it for your needs but I myself have used this to find a exe installer that was installed with random product code and random path to uninstall.exe.
    • Ok! iam going to search trough the script... thx!!
    • Yes... this is the one i can work with!! many thanks!!
Please log in to comment
This content is currently hidden from public view.
Reason: Removed by user request
For more information, visit our FAQ's.

0

Sollution:

Function GetProductCode(strName)

 

Dim strComputer, oReg, strKeyPath, strValueNAme, strValue, arrSubKeys, subkey

 

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

arrSubKeys = Null

 

Set ObjShell = CreateObject("WScript.Shell")

 

ObjShell.LogEvent 4, "Seaching in registry for installed products by search term: " & strName 

 

 

 

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 

   strComputer & "\root\default:StdRegProv")

 

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

 

If Not IsNull(arrSubKeys) Then

For Each subkey In arrSubKeys

  ' WScript.Echo subkey

   strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey

strValueName = "DisplayName"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

 

If InStr(LCase(strValue), LCase(strName)) > 0 Then

 

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey

strValueName = "UninstallString"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

ObjShell.LogEvent 4, "Found Installed "& strName &" product Code: " & Replace(Replace(strValue, "MsiExec.exe /X",""), "MsiExec.exe /I","")

If strValue <> "" Then

GetProductCode = Replace(Replace(strValue, "MsiExec.exe /X",""), "MsiExec.exe /I","")

End If 

End If

Next

End If 

arrSubKeys = Null

 

ObjShell.LogEvent 4, "Seaching in Wow6432Node registry for installed products by search term: " & strName 

 

strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

 

If Not IsNull(arrSubKeys) Then

 

For Each subkey In arrSubKeys

  ' WScript.Echo subkey

   strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey

strValueName = "DisplayName"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

 

If InStr(LCase(strValue), LCase(strName)) > 0 Then

 

strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey

strValueName = "UninstallString"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

ObjShell.LogEvent 4, "Found Installed "& strName &" product Code: " & Replace(Replace(strValue, "MsiExec.exe /X",""), "MsiExec.exe /I","")

If strValue <> "" Then

GetProductCode = Replace(Replace(strValue, "MsiExec.exe /X",""), "MsiExec.exe /I","")

End If 

End If

Next

End If 

End Function
Answered 06/19/2012 by: showitself
Senior Purple Belt

Please log in to comment
Answer this question or Comment on this question for clarity