473,805 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\\MyCo mpany\\Connecti ons"
Reg = Registry.LocalM achine.OpenSubK ey(KeyValue, True)
Value = Reg.GetValue("D atabase", "")
MsgBox(Value)
Reg.Close()

Catch ex As Exception
MsgBox(ex.Messa ge)
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.LocalM achine.OpenSubK ey(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 8463
* =?Utf-8?B?VGhvbWFz?= <Th****@discuss ions.microsoft. com> scripsit:
Dim KeyValue As String = "Software\\MyCo mpany\\Connecti ons"


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.Curren tUser.CreateSub Key("Software\M yCompany\Connec tions")

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\\MyCo mpany\\Connecti ons"
Reg = Registry.LocalM achine.OpenSubK ey(KeyValue, True)
Value = Reg.GetValue("D atabase", "")
MsgBox(Value)
Reg.Close()

Catch ex As Exception
MsgBox(ex.Messa ge)
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.LocalM achine.OpenSubK ey(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.Curren tUser.CreateSub Key("Software\M yCompany\Connec tions")

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\\MyCo mpany\\Connecti ons"
Reg = Registry.LocalM achine.OpenSubK ey(KeyValue, True)
Value = Reg.GetValue("D atabase", "")
MsgBox(Value)
Reg.Close()

Catch ex As Exception
MsgBox(ex.Messa ge)
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.LocalM achine.OpenSubK ey(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****@discuss ions.microsoft. com> scripsit:
Dim KeyValue As String = "Software\\MyCo mpany\\Connecti ons"


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
4092
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 to a handle to the following pipe: \Device\LanmanRedirector\<MACHINE>\PIPE\winreg Even after explicitly calling Close() (which, according to the docs, should not matter for a base key), and expliticly doing garbage collections, I cannot seem...
2
2519
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
4487
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
1322
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 opposed to the environment for the system I am retrieving the key from). This is easily reproduced with a small sample. Is this a known bug? It should either it expanded based on the remote environment, or not expand at all. Joe
0
1140
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
14836
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 = "SOFTWARE\\Microsoft\\.NETFramework\\AssemblyFolders"; RegistryKey thisKey = Registry.LocalMachine;
0
2855
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 the following
0
3274
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. The security permissions are identical on these two keys. Here is my code: RegistryKey...
5
4674
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 bizarre error, so I'm uncertain what should be returned on both success or failure! Thanks! Jack
3
1418
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 place). I have looked at the RegistryPermission class but would really like to see a code sample on this. How can it be done, simplest way possible? thanx
0
9718
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10617
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6876
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.