By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

RegistryKey.SetValue() Error....

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Does "SOFTWARE\\AICM\\Position" registry key exists ?

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Chakkaradeep" <Ch**********@discussions.microsoft.com> je napisal v
sporočilo news:C9**********************************@microsof t.com ...
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

Nov 16 '05 #2

P: n/a
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
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
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

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.