How do I read a value from the registry

Ron de bruin, Last update 10-Feb-2005

Go to my Excel tips page

 
You can use it for example to check if a certain program is installed and registered.
Most programs add things to the registry, ask the maker which key's and value's.
The example below will read the Computer Name from the registry.
You can find the keyname and value in the registry (Start>Run  regedit)
 
 
Sub Read_registry_Value()
    Dim Shell As Object
    Dim keyname As String
    Dim value As String
    Dim keyvalue As String
 
    keyname = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\" & _
              "Control\ComputerName\ActiveComputerName\"
              
    value = "ComputerName"
 
    Set Shell = CreateObject("wscript.shell")
    On Error Resume Next
    keyvalue = Shell.regread(keyname & value)
    If Err.Number <> 0 Then
        MsgBox "Invalid Registry Entry"
    Else
        MsgBox keyvalue
    End If
    On Error GoTo 0
End Sub
 

 

See also John Walkenbach's Tip 60

 

Using the GetSetting and SaveSetting Functions

http://j-walk.com/ss/excel/tips/tip60.htm

 

 

You can also use API to read from the registry

 

Look at the following site for a example from Dev Ashish & Terry Kreft.

http://www.mvps.org/access/api/api0015.htm