vbscript :  need a way to check the existence of of a registry key

Posted on 2006-06-08
Last Modified: 2012-05-05
Is there something like fso.fileexists but for registry keys instead of files ?
Question by:itbabe
    LVL 23

    Expert Comment

    I think you have to write code to check if it exists.  I did something like this before (to check if an application was installed by looking for it in the registry).  You could try something like that.  Here's the code:


    If isInstalled("Mozilla Firefox (1.0.4)") Then
        MsgBox("The application is installed :)")
         MsgBox("The application is NOT installed :(")
    End If

    Function isInstalled(strAppName)
         Const HKEY_LOCAL_MACHINE = &H80000002
         retVal = false
         strComputer = "."
         strAppName = LCase(strAppName)
         Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
         strComputer & "\root\default:StdRegProv")
         strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
         oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
         For Each subkey In arrSubKeys
              'MsgBox(subkey) 'uncomment this line for demo purposes
              If strAppName = LCase(subkey) Then
                   retVal = true
                   Exit For
              End If
         isInstalled = retVal
    End Function

    LVL 1

    Accepted Solution

    Hi itbabe,

    You'll find a script here which allows you to confirm the existence of a registry key using the regread command in WSH.

    There is some concern over error handling so another script can be found here:

    LVL 2

    Expert Comment

    we use a script that check the registry if SMS client is installed hope this helps:

    Option Explicit
    on error resume next
    Dim WSHShell
    Dim RegKey
    Dim waarde
    Dim wshEnvironment
    Dim strRunProgram
    Set WSHShell = CreateObject("WScript.Shell")
    Set wshEnvironment = wshShell.Environment("System")
    RegKey = "HKLM\SOFTWARE\Microsoft\SMS\Mobile Client\"
    waarde = WSHShell.RegRead(RegKey & "AssignedSiteCode")
    if not waarde = "123" Then

    Call installsms
    WScript.echo "SMS Client is geinstalleerd"
    End If

    Function installsms()
    strRunProgram = "\\1234\SMSClient\i386\client.msi"
    WshShell.Run strRunProgram, 1, True

    End Function

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    A short article about a problem I had getting the GPS LocationListener working.
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now