VB.NET read a value from a registry key HKEY_LOCAL_MACHINE

jim brown 271 Reputation points
2022-01-04T20:17:12.24+00:00

I would like to know the proper way to read a value from a registry key HKEY_LOCAL_MACHINE?

sample code that returns null or blank:

Dim readValue = My.Computer.Registry.GetValue(  
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "ProductReleaseIDs", Nothing)  
 MsgBox("The value is " & readValue)  

sample code that returns ProductReleaseIDs name not value:

Dim readValue = My.Computer.Registry.LocalMachine.GetValue(  
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "ProductReleaseIDs", Nothing)  
 MsgBox("The value is " & readValue)  

Working code for HKEY_CURRENT_USER:

Dim readValue = My.Computer.Registry.GetValue(  
"HKEY_CURRENT_USER\Software\MyApp", "Name", Nothing)  
 MsgBox("The value is " & readValue)  

Thought?: how-to-read-a-value-from-a-registry-key

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,521 Reputation points
    2022-01-04T20:34:02.773+00:00

    For example :

                Dim sPathKey As String = "SOFTWARE\Microsoft\Office\ClickToRun\Configuration"
                Using rkLocalMachine As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
                    Using rk As RegistryKey = rkLocalMachine.OpenSubKey(sPathKey, False)
                        Dim sValue As String = CStr(rk.GetValue("ProductReleaseIDs", 0))
                        Console.WriteLine("Value : {0}", sValue)
                    End Using
                End Using
    

1 additional answer

Sort by: Most helpful
  1. jim brown 271 Reputation points
    2022-01-04T20:38:48.177+00:00

    Thank you, so much!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.