Get Registry Value

  • Thread starter Thread starter Jose
  • Start date Start date
Here is an example (with some debug info that you can leave out). It is now
restricted to String type entries. You must add the 'Windows Script Host
Object Model' to your references (via Tools => References)

Public Function ReadRegisteryKey(RKey As String) As String
Dim oKey As New IWshShell_Class ' Windows Script Host Object Model
library
Dim RKeyValue As String
Dim RegVal As Variant, Entry As Variant
On Error Resume Next
RegVal = oKey.RegRead(RKey)
If Not RegVal = Empty Then
If TypeName(RegVal) = "String" Then
RKeyValue = RegVal
'Else
' Debug.Print TypeName(RegVal)
' For Each Entry In RegVal
' Debug.Print Entry
' Next
End If
End If
If Err.Number <> 0 Then
'Debug.Print Err.Number & ": " & Err.Description
ReadRegisteryKey = vbNullString
Err.Clear
Else
ReadRegisteryKey = RKeyValue
End If
Set oKey = Nothing
End Function


Public Function WriteRegisteryKey(RKey As String, Value As Variant) As
Boolean
Dim oKey As New IWshShell_Class ' Windows Script Host Object Model
library
Dim RKeyValue As String
Dim RegVal As Variant, Entry As Variant
On Error Resume Next
Call oKey.RegWrite(RKey, Value)
If Err.Number <> 0 Then
'Debug.Print Err.Number & ": " & Err.Description
WriteRegisteryKey = False
Err.Clear
Else
WriteRegisteryKey = True
End If
Set oKey = Nothing
End Function
 
Hi Vicent

I create the function as below

Public Function getKeyvalue()
Dim strValue
strValue = "HKEY_LOCAL_MACHINE\SOFTWARE\JLP\JLP_PASM2009\Version"
ReadRegisteryKey (strValue)
End Function

I run it but doesn't show the value.

What is wrong?

Thanks
Jose
 
Hi Jose,

Try again with a back-slash at the end of your argument
You may also want to look at the standard MsAccess functions "GetSetting" en
"SaveSetting"

Vincent
 
Back
Top