473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

RegistryKey.SetValue() Error....

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
2 5246
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: R A | last post by:
Hi I write the registry value using the following: Size size = new Size (100, 500); Key.SetValue (ClientSizeName, size); How can I retreive the value back to a Size type? When I use
7
by: Bob | last post by:
I'm working on a Windows app that needs to write to the Registry HKLM. I keep getting a "System.UnauthorizedAccessException: Cannot write to the registry key." error when running the app. I'm...
0
by: csharp_helpwanted | last post by:
steps.. first, I'm creating a connection by mapping a network drive to the pc second, the map drive connection was successful I try to read a certian registry key/value (that is a valid reg...
0
by: g82martin | last post by:
I am using the RegistryKey class to access the registry on remote machines. I only require read access. I am able to successfully read registry keys under HKLM\Software\Microsoft\Windows...
1
by: Chakkaradeep | last post by:
Hi all, heres my code, *******//////////////////////Starts Here////////////////////////////////////********* try { RegistryKey rKey =...
1
by: jw56578 | last post by:
Im trying to use FieldInfo.SetValue to set the values of fields in a class, the class is using reflection on itself to popluate its own fields. but i keep getting this error. Object type cannot...
6
by: Mindy | last post by:
Hey, I am using SetValue to change the DataEntry property of a form to "YES". But It doesn't work. No error messages, but the property didn't change.Following is the what I am writing SetValue:...
4
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. Here is my problem. I have a program that will create a registry key, however it is not and here is the code and also the error that follows: ...
0
by: shafikhan | last post by:
i have an visual studio 2003 iam doing asp.net i am trying to change the header and footer text in printpreview while runtime. please help me...! here iam trying to print my name as footer ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.