Home > VB and VBScript > VBScript Function to Determine if a Registry Entry Exists

VBScript Function to Determine if a Registry Entry Exists

June 15th, 2005

The following function, when called with the path to a Windows
Registry entry, will attempt to tell you if that entry exists in the
Registry of the system it’s running on.

For example, you might
call it as follows:

theEntry =
“HKLM\Software\Microsoft\Internet Explorer\Main\Start Page”
if regEntryExists(theEntry) then
   msgbox “That
Registry Entry exists.”
else
   msgbox
“That Registry Entry doesn’t exist.”
endif

The function returns a true or false
Boolean response.  True if the Registry entry exists, False if it
doesn’t.


‘ This
function returns a “true/false” response if a
‘ given
Windows Registry key exists.

‘ Since a script will generate
an error if it attempts
‘ to read a non-existent Windows Registry
key, we use
‘ a local “on error resume next” to keep
executing
‘ normally if the error occurs.

Function
RegEntryExists(theEntry)
  On error resume next
 
set shell = CreateObject(”WScript.Shell”)
  entry =
shell.RegRead(theEntry)
  If Err.Number <> 0 then
    Err.Clear
    RegEntryExists =
FALSE
  else
    Err.Clear
    RegEntryExists = TRUE
  end if
  set shell = Nothing
End Function


admin VB and VBScript , , , , , , , , , , ,

  1. No comments yet.
  1. No trackbacks yet.