Registry reading problems?

techwiz24

Well-known member
Joined
Jun 2, 2010
Messages
51
Programming Experience
Beginner
I am trying to launch another executable from a path stored in the registry. When testing my code, I get an error: "Object reference not set to an instance of an object."

My code is:
VB.NET:
Module Module1

    Sub Main()
        Dim readValue As String
        readValue = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\amake32", "GUI_PATH", Nothing).ToString
        Console.WriteLine("The value is " & readValue)
    End Sub

End Module
Any suggestions?
 
Last edited:
If you're getting a NullReferenceException then that suggests that there is no value named GUI_PATH under the HKEY_LOCAL_MACHINE\Software\amake32 key.

Hmmm... if only there was a place where you could search for information on the internet using just a few words.

console application.startuppath - Google Search

Assembly.GetEntryAssembly().Location will give you the same value as Application.ExecutablePath would. You can then use IO.Path.GetDirectoryName to get the folder and then IO.Path.Combine to append a relative path.
 
I forgot...I don't want to use the startup path method, because the console app will be called from the windows directory so it can be called from any directory...

as for the retistry, here's a snapshot of what I'm trying to get to...
registry.jpg
 
I just tried your exact code, although changing the leaf key and value names to something that exists on my own machine, and it worked fine. Do you get the same exception if you try reading a value under a different subkey of HKLM\SOFTWARE?
 
got same exception untill I changed it to:
VB.NET:
My.Computer.Registry.LocalMachine.GetValue("7-Zip", "Path", Nothing)
but that only returns the text in the second field, ie: "Path", not the actual value of "Path"...Used this code and got the same result with my key from the pic above...it only returned the name of the value, not the actual value itself...now what?

---EDIT---
Never mind, I got environment Variables to work LOL, I was typing the wrong var in XD, i'll use those instead of the registry. Thanks guys!
 
Last edited:
Back
Top