Most likely, the problem is in the parameter
Nothing
. This is a null pointer, and it's not possible to figure out what type do you imply, because there is more than one method named
RegQueryValueEx
, and this
Nothing
can be interpreted as one or another type, because your
Nothing
might mean any reference.
What to do? I don't know your declarations (please see my comment to the question; is it P/Invoked Windows API? Why?), but you need to use either array of bytes of the instance of
StringBuilder
. Declare a variable of one and another type, initialize it with
Nothing
and pass this explicitly defined variable to the method. This is a usual way of resolving such issues.
There are other problems in this code. You return the return result of this method, which is integer, but
ValueExists
expects Boolean.
However,
you don't need that stuff at all. Use the .NET class
Microsoft.Win32.Registry
and related classes, stop torturing yourself:
http://msdn.microsoft.com/en-US/library/microsoft.win32.registry.aspx[
^].
[EDIT #1]
Answering a follow-up question:
Cleaning the registry is not easy and not safe. I would start from finding a good registry repair program. And such program should be the one which can backup all the registry and restore it. As you can screw up the registry to the point where you cannot boot or normally operate your OS, this repair program should boot its own OS from a flash drive or something.
I don't know what exactly to use but 100% sure this is possible. I would start looking from here:
http://en.wikipedia.org/wiki/List_of_data_recovery_software[
^],
http://en.wikipedia.org/wiki/List_of_tools_to_create_Live_USB_systems[
^],
http://en.wikipedia.org/wiki/System_Restore[
^].
It's hard to say where to start with the registry clean up. I have tried only a limited subset of cleaning. For example, you can locate all references to file system objects and detect those pointing to non-existing files/directories. These entries should be eventually removed, but first, you need to walk the registry to remove the entries where the entries you would remove are used and do it all recursively. Again, this is not easy and not safe. Thoroughly plan each step and theoretically calculate possible adverse effects, back up…
[EDIT #2]
Sorry, probably I did not get it: if you not going to modify the registry, you are safe. Anyway, I hope the notes of [EDIT #1] could be useful.
—SA