I have this piece of code
that used to work but for some reason it writes to current root - virtual store - machine and then the node but it also reads from there and my code for reading(when app starts up) is
Is this a windows 7 thing or is the code just wrong?
Code:
public bool Write(string KeyName, object Value)
{
try
{
// Setting
string subKey1 = "SOFTWARE\\QwixAssets";
RegistryKey rk = Registry.LocalMachine;
RegistryKey sk1 = rk.CreateSubKey(subKey1);
//rk.CreateSubKey(subKey);
// Save the value
sk1.SetValue(KeyName.ToUpper(), Value);
return true;
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Writing registry " + KeyName.ToUpper().ToString());
return false;
}
}
Code:
public string GetRegistryValue(string KeyName)
{
// Opening the registry key
string subKey = "SOFTWARE\\QwixAssets";
RegistryKey rk = Registry.LocalMachine;
RegistryKey sk = rk.OpenSubKey(subKey);
if (sk == null)
{
MessageBox.Show("Problem in the Registry Source");
return null;
}
else
{
try
{
return (string)sk.GetValue(KeyName.ToUpper().ToString());
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Reading registry " + KeyName.ToUpper().ToString());
return null;
}
}
}
Comment