PDA

View Full Version : c# Reading from registry


tunacha
11-10-2009, 10:37 PM
Well ive been trying to read a install path of this program from the registry all day and i cant seem to get it to work i keep getting unhandled exceptions''

So i was wondering if anyone could at least tell me what im doing wrong so ican tr7y to learn how to fix it, this is my first time trying o do anything with the registry in c# or any programming language so any help would be appreciated

Heres the code i have made to try to do this
ive added comments to each part aswell

//Registry read
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"\Software\Joymax\Silkroad");
string sro_path = Convert.ToString(key.GetValue("InstallPath".ToString()));
// Start silkroad
System.Diagnostics.Process sro = new System.Diagnostics.Process();
sro.StartInfo.FileName = sro_path + @"\silkroad.exe";
sro.Start();

oracleguy
11-10-2009, 10:52 PM
Well, what are the exceptions you are getting? And on what line are they being thrown from?

tunacha
11-10-2009, 11:23 PM
i have solved this problem on my own with the following code

RegistryKey SROKEY;
RegistryKey SROINS = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "");
string spth = "Software\\Joymax\\Silkroad";
SROKEY = SROINS.OpenSubKey(spth);
object srph = SROKEY.GetValue("InstallPath");
System.Diagnostics.Process sro = new System.Diagnostics.Process();
sro.StartInfo.FileName = srph + @"\silkroad.exe";
sro.Start();