Registry Access - 32 vs 64 bit Mode RRS feed

  • Question

  • This is a form with a button and a multiline textbox


    Option Strict On
    Imports Microsoft.Win32
    Public Class Form1
        Const RegKey As String = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Using rk As RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey(RegKey, False)
                Dim O As Object
                Dim RegTypes As New List(Of String)
                Dim Names As New List(Of String)
                Dim Kind As RegistryValueKind
                Dim Padlength As Integer = 0
                For Each S As String In rk.GetValueNames
                    O = rk.GetValue(S, Nothing)
                    If Not O Is Nothing Then
                        Kind = rk.GetValueKind(S)
                        If Kind = RegistryValueKind.Binary Then
                            RegTypes.Add(Kind.ToString & " (" & DirectCast(O, System.Array).Length.ToString & ")")
                        End If
                    End If
                For Each Name As String In Names
                    If Name.Length > Padlength Then Padlength = Name.Length
                Padlength += 2
                TextBox1.Text = "Contents of HKLM\" & RegKey & vbNewLine & vbNewLine
                TextBox1.AppendText("Entry Name".PadRight(Padlength + 3) & "Entry Type" & vbNewLine)
                For I As Integer = 0 To Names.Count - 1
                    TextBox1.AppendText((I + 1).ToString("00") & "-" & Names(I).PadRight(Padlength) & RegTypes(I) & vbNewLine)
            End Using
        End Sub
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            Me.Text = "Running in " & (IntPtr.Size * 8).ToString & "bit Mode"
        End Sub
    End Class

    Why are the results different in "Any CPU" versus "x86"? My Computer is 64 bit

    Friday, December 27, 2019 10:31 PM


  • What this is, when compiled between any cpu and 64 bit values are read from different locations in the registry.

    32-bit and 64-bit Application Data in the Registry Registry Redirector

    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.

    profile for Karen Payne on Stack Exchange

    • Marked as answer by Devon_Nullman Saturday, December 28, 2019 5:32 AM
    Saturday, December 28, 2019 3:07 AM

All replies