By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,499 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
* =?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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.