473,473 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What status returned from RegistryKey.OpenSubKey?

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
Nov 21 '05 #1
5 4643
What is the return value if the requested subkey doesn't exist??
Nothing

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!


You have to ensure that the return value isn't Nothing before trying
to call GetType on it.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
Hmmm... I just tried an OpenSubKey on a key I know doesn't exist, and the
return is NOT null... ?? Same for a key that I know exists, so testing for
Null on the return isn't a valid test.

Is there a valid test? I try a GetType on the non-null return and get
another error, so getType doesn't work on whatever is returned.

Suggestions?
Jack
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
What is the return value if the requested subkey doesn't exist??


Nothing

Nov 21 '05 #3
Jack,
Hmmm... I just tried an OpenSubKey on a key I know doesn't exist, and the
return is NOT null... ?? Remember that C#'s "null" is the same as VB.NET's Nothing. Not to be
confused with DBNull or an SQL Null.
Can you post the code you are attempting to use to determine if the Registry
Key exists? (the code that is not working for you).

As Mattias states, RegistryKey.OpenSubKey returns Nothing if the subkey
does not exist.
Can you post how you are attempting to use GetType, as there is both a
GetType keyword and a GetType method.

Dim key As RegistryKey
Dim type As Type = GetType(System.String)
type = key.GetType()

For details on OpenSubKey see:

http://msdn.microsoft.com/library/de...bkeytopic1.asp

http://msdn.microsoft.com/library/de...bkeytopic2.asp

For an example to determining whether a registry key exists:
http://msdn.microsoft.com/library/de...ykeyexists.asp

Hope this helps
Jay

"Steve Bottoms" <sp**********@hotmail.com> wrote in message
news:Oy**************@TK2MSFTNGP14.phx.gbl... Hmmm... I just tried an OpenSubKey on a key I know doesn't exist, and the
return is NOT null... ?? Same for a key that I know exists, so testing
for Null on the return isn't a valid test.

Is there a valid test? I try a GetType on the non-null return and get
another error, so getType doesn't work on whatever is returned.

Suggestions?
Jack
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
What is the return value if the requested subkey doesn't exist??


Nothing


Nov 21 '05 #4
Yeah, I was using the wrong bloody test... Started using IsNothing() and it
works as expected now... :)

Thanks for the help! :)

Jack
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Jack,
Hmmm... I just tried an OpenSubKey on a key I know doesn't exist, and the
return is NOT null... ??

Remember that C#'s "null" is the same as VB.NET's Nothing. Not to be
confused with DBNull or an SQL Null.
Can you post the code you are attempting to use to determine if the
Registry Key exists? (the code that is not working for you).

As Mattias states, RegistryKey.OpenSubKey returns Nothing if the subkey
does not exist.
Can you post how you are attempting to use GetType, as there is both a
GetType keyword and a GetType method.

Dim key As RegistryKey
Dim type As Type = GetType(System.String)
type = key.GetType()

For details on OpenSubKey see:

http://msdn.microsoft.com/library/de...bkeytopic1.asp

http://msdn.microsoft.com/library/de...bkeytopic2.asp

For an example to determining whether a registry key exists:
http://msdn.microsoft.com/library/de...ykeyexists.asp

Hope this helps
Jay

"Steve Bottoms" <sp**********@hotmail.com> wrote in message
news:Oy**************@TK2MSFTNGP14.phx.gbl...
Hmmm... I just tried an OpenSubKey on a key I know doesn't exist, and the
return is NOT null... ?? Same for a key that I know exists, so testing
for Null on the return isn't a valid test.

Is there a valid test? I try a GetType on the non-null return and get
another error, so getType doesn't work on whatever is returned.

Suggestions?
Jack
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

What is the return value if the requested subkey doesn't exist??

Nothing



Nov 21 '05 #5
Steve,

"Steve Bottoms" <sp**********@hotmail.com> schrieb:
Yeah, I was using the wrong bloody test... Started using IsNothing() and
it works as expected now... :)


I prefer 'If ... Is Nothing Then...' for reference types.

--
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 #6

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

Similar topics

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...
8
by: Steve | last post by:
I am using RegistryKey reademai2 = Registry.LocalMachine.OpenSubKey(launch_email_path, true); string launch_email = (String)reademai2.GetValue(""); To get the value, in the registry, value =...
1
by: Abhijit | last post by:
Hi, I am facing problem in retriving value of a registry key where the value is of type REG_QWORD. Below is the code snipet i am trying with: RegistryKey reg = Registry.CurrentUser;...
4
by: Thomas | last post by:
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...
9
by: Just Me | last post by:
Public Shared Function GetValue(ByVal keyName As String, ByVal valueName As String, Optional ByVal badKey As Object = "") As Object Dim UserKey As RegistryKey =...
2
by: auldh | last post by:
being a novice i searched the net to get help on my c# project. i'm trying to iterate, enumerate, loop through a registry tree hive. for example i have a sub folder under HKLM\SOFTWARE that has...
4
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. Here is my problem. I have a program that will create a registry key, however it is not and here is the code and also the error that follows: ...
2
by: Jerry Spence1 | last post by:
I am trying to get registry information from another PC that is not part of a domain.I have tried the following: Dim key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,...
1
by: Judith Schmidt | last post by:
Hi i need a way to set permission on a registry key where i have got not rights to open it. But i am the owner (administrator). The following code fails on OpenSubKey() with...
0
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,...
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...
1
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,...
0
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.