Peering into the system registry gives you a glimpse into your operating system's critical settings. These settings, called keys, control the way Windows works. Developers use VBScript and other tools to examine and modify the keys. If you need to verify that a specific key exists before performing a registry operation, you can create a short VBScript function that queries the registry.
- Skill level:
- Moderately Easy
Other People Are Reading
Open Notepad or a text editor and paste the following VBScript code into a new document:
Dim key Name
key Name = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\"
If KeyFound(keyName) = True Then
Wscript.echo "Key exists"
Else Wscript.echo "Key does not exist"
The variable "keyName" holds the name of the registry key for which you need to search. Replace "Name" with a key of your choice. The next line of code passes that name to a function called "KeyFound." That function checks to see if the key exists.
Add this code below the code shown in the last step:
function KeyFound(byval key Name)
key Found = false
Dim right Character
right Character = right(key Name, 1)
if right Character <> "\" Then key Name = key Name & "\"
on error resume next
createobject("wscript.shell").reg Read trim(keyName)
select case err
case 0: key Found = true
This is the "KeyFound" function. It adds a slash to the end of the key if none exists and executes the "regRead" method. The "on error" statement allows the program to continue running even if the "regRead" method fails to locate the desired registry key. If the method finds a key, the code sets the value of "keyFound" to true.
Save the file with the VBS extension. For instance, if you want to name it "CheckKeys," save it as "CheckKeys.vbs."
Launch Windows Explorer and locate the file. Double-click that file to run the program. It executes and displays "Key exists" if it finds the key or "Key does not exist" if it doesn't.
Tips and warnings
- The essential part of this program is the "KeyFound" function. Simply call it from any other VBScript program, and pass the "KeyFound" function the name of any key. The function returns "True" or "False," depending on whether or not the key exists.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for