Answered Regedit

passie

Member
Joined
Mar 11, 2009
Messages
6
Programming Experience
1-3
Hello,
currectly i am making a launcher for my game now i was wondering how i put the value that i got from regedit and "main.exe" togher.

like for example

C:/games/fxmu/main.exe so full direction and application name.
this i have to select the regedit and how i run the main.exe

VB.NET:
Dim regKey As RegistryKey
Dim ver As String
regKey = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\SOFTWARE\FXMU", True)
ver = regKey.GetValue("Location")

Process.Start("main.exe")

hope someone got solution fast because i need it quickly.

~passie
 
Last edited:
You're duplicating your hive name:
VB.NET:
regKey = Registry.[B][U]LocalMachine[/U][/B].OpenSubKey("[B][U]HKEY_LOCAL_MACHINE[/U][/B]\SOFTWARE\FXMU", True)
The Registry class has a property for each hive, e.g. LocalMachine, that return RegistryKey objects. If you have a RegistryKey object that represents the HKEY_LOCAL_MACHINE hive and you want to open a subkey of that, you don't then include the name of the hive in the path of that subkey. You are effectively referring to the key at "HKEY_LOCAL_MACHINE\HKEY_LOCAL_MACHINE\SOFTWARE\FXMU", which of course doesn't exist.

Also, if all you want to get from a key is a single value then there's an easier way to do it:
VB.NET:
My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\FXMU", _
                              "Location", _
                              Nothing)
Note that in this case you DO use the full path of the key because you're not calling the method on an object that already represents the hive. The Microsoft.Win32.Registry class has a GetValue method that works in exactly the same way.
 
Back
Top