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

RegistryKey:- Object reference not set to an instance of an object

Hi All,

When i am trying run the following code i am geting the error 'Object
reference not set to an instance of an object'

Try
Dim Reg As RegistryKey
Dim Value As String
Dim KeyValue As String = "Software\\MyCompany\\Connections"
Reg = Registry.LocalMachine.OpenSubKey(KeyValue, True)
Value = Reg.GetValue("Database", "")
MsgBox(Value)
Reg.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

The following code was working my previous computer. i recently transfered
all my development projects into newly buit computer. i know why i am getting
the Object reference error because

Reg = Registry.LocalMachine.OpenSubKey(KeyValue, True)

the above line is returing Nothing. also when i test this the key is not in
registry. but i passing True to create the key if it is not found. i think
this some sort of security or permission issue.

can you please help me on this?

thanks


Nov 21 '05 #1
4 8424
* =?Utf-8?B?VGhvbWFz?= <Th****@discussions.microsoft.com> scripsit:
Dim KeyValue As String = "Software\\MyCompany\\Connections"


Replace the "\\" with "\".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
Thomas,

Did you try this one
Reg = Registry.CurrentUser.CreateSubKey("Software\MyComp any\Connections")

I hope this helps?

Cor
When i am trying run the following code i am geting the error 'Object
reference not set to an instance of an object'

Try
Dim Reg As RegistryKey
Dim Value As String
Dim KeyValue As String = "Software\\MyCompany\\Connections"
Reg = Registry.LocalMachine.OpenSubKey(KeyValue, True)
Value = Reg.GetValue("Database", "")
MsgBox(Value)
Reg.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

The following code was working my previous computer. i recently transfered
all my development projects into newly buit computer. i know why i am getting the Object reference error because

Reg = Registry.LocalMachine.OpenSubKey(KeyValue, True)

the above line is returing Nothing. also when i test this the key is not in registry. but i passing True to create the key if it is not found. i think
this some sort of security or permission issue.

Nov 21 '05 #3
thanks it works now. Basically we have to use CreateSubKey.

"Cor Ligthert" wrote:
Thomas,

Did you try this one
Reg = Registry.CurrentUser.CreateSubKey("Software\MyComp any\Connections")

I hope this helps?

Cor
When i am trying run the following code i am geting the error 'Object
reference not set to an instance of an object'

Try
Dim Reg As RegistryKey
Dim Value As String
Dim KeyValue As String = "Software\\MyCompany\\Connections"
Reg = Registry.LocalMachine.OpenSubKey(KeyValue, True)
Value = Reg.GetValue("Database", "")
MsgBox(Value)
Reg.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

The following code was working my previous computer. i recently transfered
all my development projects into newly buit computer. i know why i am

getting
the Object reference error because

Reg = Registry.LocalMachine.OpenSubKey(KeyValue, True)

the above line is returing Nothing. also when i test this the key is not

in
registry. but i passing True to create the key if it is not found. i think
this some sort of security or permission issue.


Nov 21 '05 #4
thanks it works now. Basically we have to use CreateSubKey.

"Herfried K. Wagner [MVP]" wrote:
* =?Utf-8?B?VGhvbWFz?= <Th****@discussions.microsoft.com> scripsit:
Dim KeyValue As String = "Software\\MyCompany\\Connections"


Replace the "\\" with "\".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

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

Similar topics

0
by: geek_in_a_box | last post by:
I seem to be experiencing a behavior on Framework 1.0 sp2 RegistryKey class where the class is not releasing/closing named pipe winreg handles to remote machines. The process continues to hold on...
2
by: =JT= | last post by:
I would like to get the HKEY(a handle to the registry key) from the RegistryKey class in C#, but it does not seem to be exposed. is it possible?
1
by: R Agam | last post by:
Hi How can I tell what type of value (string, int, ...) is returned from a call to RegistryKey.GetValue? Thanks, Ronen
0
by: Frank Jones | last post by:
When I call RegistryKey.GetValue for a remote system, it returns a value that has been automatically expanded for me using the environment of the machine that is running the .Net application (as...
0
by: Bruce | last post by:
Is there any way to determine a registry key's type (DWORD, string, multi-string, etc.) when using the RegistryKey class to read keys? Bruce
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...
5
by: Steve Bottoms | last post by:
Hi, all... Trying to determine how to check the state of OpenSubKey when called. What is the return value if the requested subkey doesn't exist?? I try a GetType on the result but only get a...
3
by: marcussilfver | last post by:
How can I set write permissions for a limited user to write values to a certain registrykey. This registrykey is also written to by a administrator (which probably also created the key in the first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
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,...

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.