none
Problem accessing registry value RRS feed

  • Question

  • I am trying to access the value "Manufacturer" in the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation

    Here is the code I used:

            Dim wkValue As String
            Dim wkKeyHKLM = "HKEY_LOCAL_MACHINE\"
            Dim wkSubKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation"
            wkValue = My.Computer.Registry.GetValue(wkKeyHKLM & wkSubKey, "Manufacturer", "Not Found")
            MsgBox(wkValue)

    "Not Found" is what displays.

    Using Registry Editor for this key

    Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation

    I see Value name: Manufacturer and Value data: Dell

    Why do I not get this when I try to get the value using the above code.

    In trying to research this scenario, I also tried the following:

            Try
                wkKey = Registry.LocalMachine.OpenSubKey(wkSubKey)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            wkValue = wkKey.Name & vbCrLf & "  SubKeys: " & wkKey.SubKeyCount.ToString
            wkValue += vbCrLf & "  Values: " & wkKey.ValueCount.ToString
            MsgBox(wkValue)

    This results in Subkeys count of 0 and Values count of 0. I guess if neither way can see the values, then why can RegEdit see them? Why does neither technique result in anything from that key?

    Wednesday, February 26, 2020 7:21 PM

Answers

  • You may need to compile as 64x rather than any cpu or x86, try that with this code.

    Try
        Using key As RegistryKey =
            Registry.LocalMachine.OpenSubKey(
                "SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation")
    
            If key IsNot Nothing Then
                Dim Manufacturer As Object = key.GetValue("Manufacturer")
                If Manufacturer IsNot Nothing Then
                    MessageBox.Show(Manufacturer.ToString())
                End If
            End If
        End Using
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Mike Lusicic Wednesday, February 26, 2020 8:19 PM
    Wednesday, February 26, 2020 7:45 PM
    Moderator

All replies

  • You may need to compile as 64x rather than any cpu or x86, try that with this code.

    Try
        Using key As RegistryKey =
            Registry.LocalMachine.OpenSubKey(
                "SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation")
    
            If key IsNot Nothing Then
                Dim Manufacturer As Object = key.GetValue("Manufacturer")
                If Manufacturer IsNot Nothing Then
                    MessageBox.Show(Manufacturer.ToString())
                End If
            End If
        End Using
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Mike Lusicic Wednesday, February 26, 2020 8:19 PM
    Wednesday, February 26, 2020 7:45 PM
    Moderator
  • I changed it to x64 and used the same code and it worked. Thanks.
    Wednesday, February 26, 2020 8:19 PM
  • I changed it to x64 and used the same code and it worked. Thanks.
    Your welcome :-)

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, February 26, 2020 8:26 PM
    Moderator