473,326 Members | 2,090 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,326 software developers and data experts.

problem save and reading from the registry

Hi,

I want to store some data in the registry, however I have not been able to
do this, and think my logic maybe flawed.

Firstly I try to open the registry and read in any existing values.
Dim aKey As RegistryKey
aKey = Registry.CurrentUser.OpenSubKey("software\myApplic ation")

I then attempt to read in any existing values
strServerName = aKey.GetValue("ServerName")
strLoginName = aKey.GetValue("LoginName")

When the first getValue is executed, i get an error 'object reference not
set to an instance of an object', which I guess is fine as this registry
entry doesn't exist yet.

If the registry entry doesn't exist (say first time the application is run),
then I capture the error on the above code and create the registry subkey=
Registry.CurrentConfig.CreateSubKey("software\myAp plication") ' No error on
this line

After the user has logged in, i want to save the user id and server name to
the registry, so that next time they use the program, step 1 will populate
the login form with the last login details used.

aKey.SetValue("ServerName", frmSPlash.txtServer.Text)
aKey.SetValue("LoginName", frmSPlash.txtUserID.Text)

When the first setvalue is execute i get an error 'object reference not set
to an instance of an object'. which i would not expect as it should be just
creating the entry.

What have I done wrong here......

THanks

Aug 24 '06 #1
3 1777
Have you looked at the app.config file? This replaces storing settings
in the registry for .NET apps. If you using VS 2005 it's very simple:

'Get Value
Value = My.Settings.[SettingsName]

'Set Value
My.Settings.[SettingsName] = Value
Aussie Rules wrote:
Hi,

I want to store some data in the registry, however I have not been able to
do this, and think my logic maybe flawed.

Firstly I try to open the registry and read in any existing values.
Dim aKey As RegistryKey
aKey = Registry.CurrentUser.OpenSubKey("software\myApplic ation")

I then attempt to read in any existing values
strServerName = aKey.GetValue("ServerName")
strLoginName = aKey.GetValue("LoginName")

When the first getValue is executed, i get an error 'object reference not
set to an instance of an object', which I guess is fine as this registry
entry doesn't exist yet.

If the registry entry doesn't exist (say first time the application is run),
then I capture the error on the above code and create the registry subkey=
Registry.CurrentConfig.CreateSubKey("software\myAp plication") ' No error on
this line

After the user has logged in, i want to save the user id and server name to
the registry, so that next time they use the program, step 1 will populate
the login form with the last login details used.

aKey.SetValue("ServerName", frmSPlash.txtServer.Text)
aKey.SetValue("LoginName", frmSPlash.txtUserID.Text)

When the first setvalue is execute i get an error 'object reference not set
to an instance of an object'. which i would not expect as it should be just
creating the entry.

What have I done wrong here......

THanks
Aug 24 '06 #2
I think the problem is that you read from a different location then you
write to:

Registry.CurrentUser.OpenSubKey("software\myApplic ation")
Registry.CurrentConfig.CreateSubKey("software\myAp plication")

Below is a working sample, hope this helps:

Greetz Peter

Dim myKey As RegistryKey
myKey = Registry.CurrentUser.OpenSubKey("Software\testNG")
If myKey Is Nothing Then
myKey = Registry.CurrentUser.OpenSubKey("Software", True)
myKey.CreateSubKey("testNG")
myKey = Registry.CurrentUser.OpenSubKey("Software\testNG", True)
myKey.SetValue("testNG", "Peter Proost")
Else
MsgBox(myKey.GetValue("testNG"))
End If

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Aussie Rules" <Au*********@nospam.nospamschreef in bericht
news:#t**************@TK2MSFTNGP02.phx.gbl...
Hi,

I want to store some data in the registry, however I have not been able to
do this, and think my logic maybe flawed.

Firstly I try to open the registry and read in any existing values.
Dim aKey As RegistryKey
aKey = Registry.CurrentUser.OpenSubKey("software\myApplic ation")

I then attempt to read in any existing values
strServerName = aKey.GetValue("ServerName")
strLoginName = aKey.GetValue("LoginName")

When the first getValue is executed, i get an error 'object reference not
set to an instance of an object', which I guess is fine as this registry
entry doesn't exist yet.

If the registry entry doesn't exist (say first time the application is
run),
then I capture the error on the above code and create the registry subkey=
Registry.CurrentConfig.CreateSubKey("software\myAp plication") ' No error
on
this line

After the user has logged in, i want to save the user id and server name
to
the registry, so that next time they use the program, step 1 will populate
the login form with the last login details used.

aKey.SetValue("ServerName", frmSPlash.txtServer.Text)
aKey.SetValue("LoginName", frmSPlash.txtUserID.Text)

When the first setvalue is execute i get an error 'object reference not
set
to an instance of an object'. which i would not expect as it should be
just
creating the entry.

What have I done wrong here......

THanks

Aug 25 '06 #3
Hi Aussie,

Additional to Peter's reply:

What you got is the NullReferenceException, which normally means that aKey
is a null reference. The simplest way is set a breakpoint in aKey.SetValue
line, and view aKey variable in Watch Window in VS.net IDE debugger.

If once you find the null reference, you should check why aKey is not
assigned a real object instance.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Emo | last post by:
Hello. I installed OpenWiki Web base application on Windows 2000 SP3, IIS 5.0 Server. When i try to connect to the OpenWiki Web page I get the following weird error message: Error: Probable...
4
by: mYsZa | last post by:
Hi all! I've got really strange (for me) problem: I've got an application, that at startup decrypts some data. Everything works fine - the rijndael key is decrypted using the...
41
by: Mountain Bikn' Guy | last post by:
What is the current preferred way to save user preferences in dotnet? Is the registry the right place to do this? Can anyone recommend a good article (or book) for this topic? Thanks.
0
by: Paul | last post by:
I am reading events from an event log on a remote server. Certain events will be put in a file or some other form of output. Everything works fine but I am concerned a potential problem. Reading...
3
by: Marauderz | last post by:
Hello guys, got a little question regarding the regional language settings . Anyway I got a Windows 2003 Server machine that was installed with the date format "dd/MM/yyyy" and location still...
5
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
1
by: fabrice | last post by:
Hello I have a little problem by reading personal registry key. I get an error System.NullReferenceException even if the key exist. This is my code. Dim objKey As RegistryKey objKey =...
1
by: method | last post by:
I am trying to delete registery key encluding all its subkeys . I want to delete the bold part HKEY_CURRENT_USER, "Software\xyz\foldername\" using an api that i found on the net but i keep...
1
by: method | last post by:
Hi all i am usiing this code to write mulitiple values to registery but it only write one value. could any one help me make this code so that it write multiple values to registery. Currently it only...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.