VBScript Registry Check

The script is set to look for folders and create them.  Then to check for a registry key path and if it doesn't exist to run an install.  It runs properly the first time through, but subsequent runs of the scripts do not run the MSI, confirmed that the key is gone, and trying to run the script without the registry check launches the MSI.

Any help is appreciated.

Dim objFSO, WshShell

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set wshShell = CreateObject("WScript.Shell")
Set objRegistry = GetObject("winmgmts:\\" & _
     strComputer & "\root\default:StdRegProv")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists("C:\Windows\TEMP\") Then
End If

If Not objFSO.FolderExists("C:\Windows\TEMP\Logs") Then
End If
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
strValueName = "{3FE28AA5-8140-47E4-A0D3-974F24831556}"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName
      If IsNull(strValueName) Then
      Wshshell.run "msiexec.exe /i <path to MSI> /qn /l*v C:\Windows\temp\Logs\GFI2012GPOInstall.log"
End If
Who is Participating?
Jared LukerConnect With a Mentor Commented:
on error goto next
KeyCheck = wshshell.regread "hklm\Software\Microsoft\Windows\CurrentVersion\Uninstall\{3FE28AA5-8140-47E4-A0D3-974F24831556}"
on error goto 0

If err.number <> 0 Then
   Wshshell.run "msiexec.exe /i <path to MSI> /qn /l*v C:\Windows\temp\Logs\GFI20
End if

Open in new window

I forget why, but I remember that checking for the EXISTENCE of a registry key using WMI is tricky.

Here is the most reliable method I've created:

Function RegValueExists(byval RegHive, byval RegKey, byval RegValue)
  Dim aValueNames, aValueTypes
  RegValueExists = False   ' init value
  If oReg.EnumValues(RegHive, RegKey, aValueNames, aValueTypes) = 0 Then
    If IsArray(aValueNames) Then
      For i = 0 To UBound(aValueNames)
        If LCase(aValueNames(i)) = LCase(RegValue) Then
          RegValueExists = True
          Exit Function
        End If
    End If
  End If
End Function

Open in new window

Jared LukerCommented:
Usually when I'm checking to see if a registry key exists, I'll just use wshshell.regread with 'on error goto next' turned on

on error goto next
KeyCheck = wshshell.regread "hklm\Software\Microsoft\Windows\CurrentVersion\Uninstall\{3FE28AA5-8140-47E4-A0D3-974F24831556}
on error goto 0

If the key exists err.number will be 0.  If it does not exist, err.number will be <> 0.

If err.number <> 0 Then
   Wshshell.run "msiexec.exe /i <path to MSI> /qn /l*v C:\Windows\temp\Logs\GFI20

See if that helps...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.