VBScript Registry Check

Posted on 2012-08-16
Medium Priority
Last Modified: 2012-09-06
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
Question by:aquias2000
  • 2
LVL 10

Expert Comment

ID: 38305041
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

LVL 17

Expert Comment

by:Jared Luker
ID: 38322266
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...
LVL 17

Accepted Solution

Jared Luker earned 1500 total points
ID: 38322270
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


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question