RegistryKey.SetValue() Error....

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

heres my code,

*******//////////////////////Starts
Here////////////////////////////////////*********
try
{
RegistryKey rKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE\\AICM\\Position",true);
rKey.SetValue("SIZE","1");
rKey.Close();

MessageBox.Show("Done with 1st Key");

rKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\AICM\\TITLE",true);
rKey.SetValue("Title","Receiving from "+str_dname);
rKey.Close();

rKey = null;
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
*******//////////////////////Ends
Here////////////////////////////////////*********

When i execute this code i get the error message,

"Object reference not set to an instgance of an object"

am not getting the first message box itself...........

what is this error and i would be happy if someone could answer....

with regards,
C.C.Chakkaradeep
 
Make sure that the key you are opening exists. Make sure that you have
security access to the key.

Use the CreateSubKey to open the key if it exists or create it and open it
if it does not exist.

Lastly, you should always check for null when accessing the registry. If
you are storing settings in the registry, always provide a default value to
use in your application when the value is not available from the registry.
You never know when your users are going to start hacking around. Which
raises another point. Always do validation on registry settings just as you
would from any user input.

If you follow the guidelines in the paragraph above, then you can, and
should, always use CreateSubKey to access your settings rather than
OpenSubKey.

HTH

DalePres
MCAD, MCDBA, MCSE
 
Back
Top