Inside Man
Inside Man

Reputation: 4309

Check if a binary registry value exists via VBScript

I have a code which checks for a registry key value that exists or not. It only works on none binary values, if the target path is a binary value then it can not checks for it and will tell that the key does not exists.

Here is the Code:

Const HKEY_CURRENT_USER = &H80000001

strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")

strKeyPath = "System\CurrentControlSet\Control\Stranger"
strValueName = "TargetBinaryKey"
objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

If IsNull(strValue) Then
WScript.Echo "The Key Does Not Exists."
Else
WScript.Echo "The Key Exists."
End If

What should I do?

Upvotes: 1

Views: 3450

Answers (1)

AutomatedChaos
AutomatedChaos

Reputation: 7490

You should use .enumValues instead of .GetStringValue. You can find a code snippet here

Addition: you could also use GetBinaryValue if you know at forehand that the value is stored as binary

Upvotes: 1

Related Questions