You're misunderstanding how GetStringValue
works. The data read from the registry value is returned via the out parameter sValue
:
retval = reg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, sValue)
If no data can be read that value is set to Null
.
The return value of the method:
retval = reg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, sValue)
is an integer indicating whether the method call succeeded or not. A return value of 0 means that the call was successful. a non-zero value means that something went wrong. A value of 2 in particular indicates that the registry key you're trying to read from doesn't exist.
Also, you must not use the Set
keyword here. That keyword must only be used when assigning objects to variables. In this case, however, the return value is a primitive data type (integer).