Check if a registry value exists in VBScript

Simple function that returns true if the specified registry value exists, and False if it does not.

Function regValueExists (key)
      'This function checks if a registry value exists and returns True of False
      On Error Resume Next
      Dim oShell
      Set oShell = CreateObject ("WScript.Shell")
      regValueExists = True
      Err.Clear
      oShell.RegRead(key)
      If Err <> 0 Then regValueExists = False
      Err.Clear
      Set oShell = Nothing
End Function

Example usage:

If regValueExists("HKCU\Software\Something\SomeValue") Then
      ' do something
End If
This entry was posted in Scripting, Windows and tagged , , , , . Bookmark the permalink.

3 Responses to Check if a registry value exists in VBScript

  1. Pingback: Outlook 2007 AutoArchive PST location change VBScript | Robin CM's IT Blog

  2. Mike says:

    The variable “regKeyExists” needs to be “regValueExists” for this to work properly. :)

    • rcmtech says:

      Ahh yes, WordPress doesn’t do find & replace (I don’t think) – I evidently missed that one. Now changed, thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s