0

I need to read the installation path of an application from its associated registry key, which in this case is "HKEY_LOCAL_MACHINE\SOFTWARE\Computers and Structures, Inc.\SAP2000\18\Install path".

I have tried the following:

ProgramPath = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Computers and Structures, Inc.\SAP2000\18", "Install path", Nothing)

With the result of Nothing.

Also tried the following:

ProgramPath = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Computers and Structures, Inc.\\SAP2000\\18\\Install path", True)

With no success either.

Here is how my registry looks like

What am I doing wrong? Could there be an issue with the blank spaces or special characters (,.) both in the "Computers and Structures, Inc." or in the "Install path"?

Any light on this would be really appreciated. Thanks in advance.

darkjmf
  • 21
  • 1
  • 4

2 Answers2

2

Eureka!!!

Eventually I discovered that although it was my intention to read from the 64bit branch of the registry ("HKEY_LOCAL_MACHINE\SOFTWARE\Computers and Structures, Inc.\SAP2000\18") all the instructions I was using were indeed accessing the 32bit branch ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Computers and Structures, Inc.\SAP2000\18") where there was no "\18" subkey, hence the error.

Once known where the mistake was, it was really easy to find a solution in https://stackoverflow.com/a/20910975/6912725

The final code resembles:

Dim regVersion64 As Microsoft.Win32.RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _
                                    (Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64).
                                    OpenSubKey("SOFTWARE\Computers and Structures, Inc.\SAP2000\18")
Dim ProgramPath As String = regVersion64.GetValue("Install path")

Thank you all for your help, and hope this thread helps other people.

Community
  • 1
  • 1
darkjmf
  • 21
  • 1
  • 4
0

this works for me

Dim txt As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion", "ProductName", "")

so if your values are all correct, try using "" rather than nothing

Rob
  • 3,488
  • 3
  • 32
  • 27
  • Thanks Rob, but it does not work for me. The result is still "Nothing". – darkjmf Oct 03 '16 at 06:04
  • There is another post here: http://stackoverflow.com/questions/9491958/registry-getvalue-always-return-null that says "If it returns null, set your build architecture to Any CPU. The operating system may virtualize 32-bit and 64-bit registries differently." - may be of help? – Rob Oct 04 '16 at 00:00