Create 64 bit registry key (non-WOW64) from a 32 bit application

前端 未结 3 668
南旧
南旧 2020-12-06 10:32

I have a Visual Studio installer that is creating some registry keys:

HKEY_LOCAL_MACHINE\\SOFTWARE\\MyApp

but the registry keys it is creat

3条回答
  •  半阙折子戏
    2020-12-06 11:02

    Since there is very little documentation about OpenBaseKey, I'll expand on shifuimam's answer and provide a solution for the OP:

    Private Sub Foo()
        Dim myAppIs64Bit = Environment.Is64BitProcess
        Dim baseKey As RegistryKey
        If (myAppIs64Bit) Then
            baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
        Else
            baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
        End If
        Dim myAppKey As RegistryKey = baseKey.OpenSubKey("SOFTWARE\MyApp")
    End Sub
    

    If the app is 32-bit, myAppKey points to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyApp. If 64-bit, it points to HKEY_LOCAL_MACHINE\SOFTWARE\MyApp.

    The advantage of OpenBaseKey is that it eliminates the need to reference Wow6432 in your code.

提交回复
热议问题