Registry.CurrentUser.CreateSubKey (creates a Key if does not exists but i want only to read)
hello every one ,
i have one big problem . if i remove my registry key from regedit then next time software automatically create registry key . but i want that if registry does not exists then software should not be open . if it possible then let me know and my code is there
RegistryKey regKeyAppRoot = Registry.CurrentUser.CreateSubKey("Software");
String GUID=(String)regKeyAppRoot.GetValue("KEY");
if (GUID == "CF91F736-2830-4233-9EC9-9C2AE482B650")
{
//code
}
else
{
MessageBox.Show("");
this.Close();
}
Its urgent Reply me As soon as Possible
Thanks in Advance

Nilanka DharmadasaPosted Nov 11, 2009, 6:43 AM
You are back..
Why don't u use opensubkey method to read the key as i mentioned in your previous thread?
RegistryKey regKeyAppRoot = Registry.CurrentUser.OpenSubKey("........");
if( (regKeyAppRoot != null) && (regKeyAppRoot.GetValue("KEY") != null){
String GUID=(String)regKeyAppRoot.GetValue("KEY");
if (GUID == "CF91F736-2830-4233-9EC9-9C2AE482B650")
{ //code }
else
{ MessageBox.Show("");
this.Close();
}
}
else{
MessageBox.Show("");
this.Close();
}
For more info go to this link.It provides a detailed explaination.
http://www.codeproject.com/KB/system/registry1.aspx?msg=812147
Kirtan PatelPosted Nov 11, 2009, 6:48 AM
Here is Rectified Code of yours
if my answer helps you then check Do you like this answer :)
RegistryKey regKeyAppRoot =Registry.CurrentUser.OpenSubKey("Software",true);
string GUID = regKeyAppRoot.GetValue("KEY", "").ToString();
if(GUID == "CF91F736-2830-4233-9EC9-9C2AE482B650")
{
MessageBox.Show("Key Matched !!");
}
else if(GUID == "")
{
MessageBox.Show("KeyNot Found!!");
//Do Whatever you want here if Key Not Found
this.Close();
}
Serban CosminPosted Nov 11, 2009, 5:01 AM