' Return a registry key value.
Private Function GetRegKeyValue(ByVal root As Long, ByVal _
key_name As String, ByVal subkey_name As String) As _
String
Dim hKey As Long
Dim value As String
Dim length As Long
Dim value_type As Long
' Open the key.
If RegOpenKeyEx(root, key_name, _
0&, KEY_QUERY_VALUE, hKey) <> ERROR_SUCCESS _
Then
MsgBox "Error opening key."
Exit Function
End If
' Get the subkey's size.
If RegQueryValueEx(hKey, subkey_name, _
0&, value_type, ByVal 0&, length) _
<> ERROR_SUCCESS _
Then
MsgBox "Error getting subkey length."
End If
' Get the subkey's value.
value = Space$(length)
If RegQueryValueEx(hKey, subkey_name, _
0&, value_type, ByVal value, length) _
<> ERROR_SUCCESS _
Then
MsgBox "Error getting subkey value."
Else
' Remove the trailing null character.
GetRegKeyValue = Left$(value, length - 1)
End If
' Close the key.
If RegCloseKey(hKey) <> ERROR_SUCCESS Then
MsgBox "Error closing key."
End If
End Function
|