View Single Post
Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Re: I want to manipulate the registry key values through a vb.net application

 
0
  #7
Oct 1st, 2008
Hi Guys

I have managed to write values to a Windows Mobile CE Registry Editor from my application.

I have a writeIniReg() and a readIniReg() function

So, when the user enters their name in the textbox on the form it is written to the registry and read from it again the next time the user runs the program.

But my problem is that my readIniReg() gets a NullReferenceException when the program first loads .... but if I comment out the readIniReg() and run it to write data to the registry then uncomment the code, it can read from it...


Can anyone help me to check in my readIniReg() if the subKey folders exist first and create them if they dont exist ... so that I can get away from my error message.

Please even give some suggestions ... I still have a lot to learn with VB

  1. Public Function readIniReg() As Boolean
  2. Dim localResult As Boolean
  3. Dim regKey As RegistryKey
  4. Dim regKeyCompany As RegistryKey
  5. Dim regKeyProduct As RegistryKey
  6.  
  7. localResult = False
  8.  
  9. regKey = Registry.CurrentUser.OpenSubKey("Software", True)
  10. regKeyCompany = regKey.OpenSubKey("Company", True)
  11. regKeyProduct = regKeyCompany.OpenSubKey("Data", True)
  12.  
  13. 'Name of value to return
  14. strName = regKeyProduct.GetValue("Username").ToString()
  15. 'Pass username string variable to form1 variable
  16. Form1_LogIn.username = strName
  17. 'Display Name in the textbox
  18. Form1_LogIn.txt_user.Text = strName
  19.  
  20.  
  21. 'Close all keys
  22. regKeyCompany.Close()
  23. regKeyProduct.Close()
  24. regKey.Close()

Regards

Elmo
Michelle (Junior Developer)
Reply With Quote