473,516 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5252
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
1898
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
14813
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 logged in as an Administrator and it's a Windows app. What permission does it need? Here's the code. private void ChangeReg() { string regPath =...
0
2832
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 item) third, I disconnect the network drive connection it works great the first time but if i run it again on the same pc anytime after that I get...
0
3201
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 NT\CurrentVersion\HotFix but I get a permissions error when I try to access HKLM\Software\Network Associates\TVD\Shared Components\VirusScan Engine\4.0.xx....
1
334
by: Chakkaradeep | last post by:
Hi all, heres my code, *******//////////////////////Starts Here////////////////////////////////////********* try { RegistryKey rKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\AICM\\Position",true);
1
1848
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 be converted to target type here is code Dim myFieldInfo() As System.Reflection.FieldInfo Dim myType As Type = Me.GetType ' Get the type and...
6
12072
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: Item: !!.DataEntry Expression:Yes Does anyone know what is wrong? Thanks.
4
1711
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: Imports System.IO Imports System.Text Imports System.Security.Cryptography Imports System.Net Imports Microsoft.VisualBasic.Conversion Imports...
0
1223
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 Dim mkey As RegistryKey = Registry.CurrentUser.OpenSubKey("software\Microsoft\Internet Explorer\pagesetup", True) Dim strr As String = "Shafikhan" ...
0
7276
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.