/build/static/layout/Breadcrumb_cap_w.png

VBS check for a value inside subkeys

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.


0 Comments   [ + ] Show comments

Answers (4)

Answer Summary:
Posted by: dugullett 12 years ago
Red Belt
4

You can use this. It is powershell though.

 
$app = gwmi win32_product | where-object { $_.name -match "ENTER NAME OF SOFTWARE" }
$app.uninstall()
 

Comments:
  • nice!! i only don't know if SCCM can execute power shell files. And this is also for MSI installations - showitself 12 years ago
    • 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 - dugullett 12 years ago
      • 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. - showitself 12 years ago
  • SP3 should have it. - dugullett 12 years ago
  • So you'll know the path everytime, or will this be something random? - dugullett 12 years ago
    • 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. - showitself 12 years ago
Posted by: dugullett 12 years ago
Red Belt
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
 
Posted by: henrik80 12 years ago
Second Degree Blue Belt
1

Comments:
  • Very nice script... only this is for checking a MSI installation with product key. Executables do not have product keys - showitself 12 years ago
  • 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. - henrik80 12 years ago
    • Ok! iam going to search trough the script... thx!! - showitself 12 years ago
    • Yes... this is the one i can work with!! many thanks!! - showitself 12 years ago
Posted by: showitself 12 years ago
Senior Purple Belt
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

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