Reputation: 13
The following VBscript code ALWAYS fails to find the specified key in the local registry, even when it's definitely there. What am I doing wrong? I'm running 32-bit XP Pro/SP3.
Dim winShell
Set winShell = CreateObject("WScript.Shell")
If regKeyExists(winShell, "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\ProgName\") Then
wscript.echo "ProgName key found"
Else
wscript.echo "Key not found!"
End If
Set winShell = Nothing
Function regKeyExists (winObj, key)
On Error Resume Next
regKeyExists = True
Err.Clear
winObj.RegRead(key)
If Err <> 0 Then regKeyExists = False
Err.Clear
End Function
The output ALWAYS reads "Key not found!", even when the key is present. I'm stumped!
Upvotes: 1
Views: 691
Reputation: 200233
Are you certain that you're actually looking for a key? Usually the Run
key contains REG_SZ or REG_EXPAND_SZ values to auto-start programs on login.
Check what happens when you change your code to look for a value ProgName
by removing the backslash after ProgName
:
If regKeyExists(winShell, "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\ProgName") Then
...
Upvotes: 3