Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET read registry

Beyond perplexed this time...

The simplest possible line of code works sometimes, sometimes it doesn't. First I thought the issue was that I was trying to read the value of a DWORD, but since I CAN read DWORD values from SOME keys, that must not be the problem. Now the problem seems to be that I can't read from ANY key if the key has a space in the name. Surely this can't be. I refuse to believe that MS didn't account for spaces in registry key paths and names.

So tell me why this doesn't work:

MsgBox(My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\CA\CA ARCserve D2D\WebService", "Port", Nothing))

It just pops up an empty box. And yes, a value does exist in the registry, and yes, I have permission to read the key.

EDIT: Yup, over and over again it seems that you can't read from the registry if there are spaces anywhere in the key name. Seriously?!?

EDIT AGAIN: "Ramhound" says code examples are stupid. Fascinating point of view. However his own suggestion also failed:

Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\ATI Technologies\CBT")

Dim objValue As Object

objValue = key.GetValue("ReleaseVersion")

MsgBox(objValue.ToString())

like image 697
Jimmy D Avatar asked Aug 05 '11 16:08

Jimmy D


1 Answers

After an entire wasted day, the solution is to set your VS project to "any cpu" in advanced compile options because if set to x86 and running on a 64bit OS you are limited to the "Wow6432node" in the registry.

like image 83
Jimmy D Avatar answered Sep 20 '22 02:09

Jimmy D