
Creating registry values (using Regobj.dll)
Hi guys,
For a program I'm writing, I use a lot of values stored in the
registry which are edited by my setup program. I'm using Regobj.dll to
edit the registry because it will let me go anywhere in the registry and
SaveSetting restricts to the Local User. My problem is this, when I
install it on a new computer that the values are not yet created, I get an
error telling me just that. The RegSetValue sub is supposed to check if
the branch exists and create it with the RegCreateValue function if it
doesn't. For some reason, this doesn't work. And I'm not able to figure
out how the code works, let alone try and fix it. Any help would be
greatly appreciated!
Brad
Sub RegSetValue(MainKey$, SubKey$, ValueName$, ValueString)
On Error GoTo RegSetValue_Err
Dim objRegKey As RegKey
Dim sCompl As String
Dim bRet As Boolean
'Make sure the SubKey and ValueName already exist in the registry
bRet = RegCreateValue(MainKey, SubKey, ValueName, ValueString)
'Now it is OK to set the value
sCompl = "\" & MainKey & "\" & SubKey
Set objRegKey = RegKeyFromString(sCompl)
objRegKey.Values(ValueName).Value = ValueString
Exit Sub
RegSetValue_Err:
End Sub
Function RegCreateValue(MainKey$, SubKey$, ValueName$, ValueString) As
Boolean
'This function creates a registry key & value. It must not already exist
'STRING values only!
'All errors are ignored in case the key exists
On Error Resume Next
Dim objRegKey As RegKey
Dim sCompl As String
sCompl = "\" & MainKey & "\" & SubKey
Set objRegKey = RegKeyFromString(sCompl)
objRegKey.Values.Add ValueName, ValueString, RegValueType.rvString
RegCreateValue = False
End Function