I need to detect if a key exists like this,

HKEY_CURRENT_USER\Software\MyCompany\MyProgram\UserName

If the key does exist, I am opening my main form;
Application.Run(new frm_Main());

Else Show.Dialog of my User Setup form.

The form launching I can handle without problem, my problem is seeing if the
key exists, and if not, then doing the redirect. I just can't seem to get
this to function properly, if the key isn't there I get a object error, if
the key is there then the app loads the main form properly.

All suggestions are greatly appreciated!

--
D @ premierdata

Re: Does Registry Key exist, if not go to form.. in C# by Maqsood

Maqsood
Wed Oct 12 23:32:06 CDT 2005

Hello,
Please see MSDN help for Microsoft.Win32.RegistryKey.GetSubKeyNames
method. You can check existance of registry key name from the array of
subkey names it returns.

HTH. Cheers.
Maqsood Ahmed - MCAD.net
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***

RE: Does Registry Key exist, if not go to form.. in C# by v-jetan

v-jetan
Mon Oct 17 02:24:53 CDT 2005

Hi premierdata,

Does Maqsood's reply make sense to you? Beside this, we can also use
RegistryKey.OpenSubKey method to access the specified key, if null
reference is returned, this key should not exist. If you have any concern,
please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


RE: Does Registry Key exist, if not go to form.. in C# by dewright_ca

dewright_ca
Mon Oct 17 09:23:03 CDT 2005

That is the direction I have been trying to go, but if the key doesn't exist
I get a exception, then if the key does exist I pass through just fine. So I
am missing something in how the pieces go together.

I am sure I am just missing something in the syntax, but everything I have
seen referenced online deals with more elaborate structures, all I am trying
to do is see if a key exists, if not do this, else continue.

--
D @ premierdata


""Jeffrey Tan[MSFT]"" wrote:

> Hi premierdata,
>
> Does Maqsood's reply make sense to you? Beside this, we can also use
> RegistryKey.OpenSubKey method to access the specified key, if null
> reference is returned, this key should not exist. If you have any concern,
> please feel free to tell me, thanks
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>
>

RE: Does Registry Key exist, if not go to form.. in C# by v-jetan

v-jetan
Mon Oct 17 20:54:13 CDT 2005

Hi dewright_ca,

Thanks for your feedback.

I am not sure why on your side, if the key does not existed, an exception
will throw. In fact, if you view OpenSubKey method reference in MSDN link
below:
"RegistryKey.OpenSubKey Method (String, Boolean)"
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfMicrosoftWin32Regist
ryKeyClassOpenSubKeyTopic2.asp

In "Remarks" section, it stated: "Rather than throwing an exception, a null
value is returned if the requested key does not exist." So there should not
be any exception thrown for registry key that does not existed.

Also, based on the test on my side, only a null reference will return for
registry key that does not exist. Can you provide some more information for
me to reproduce our your problem? Thanks

Addtionally, can you show us what exception your code throws out? Can you
provide the detailed call stack for this exception? Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


RE: Does Registry Key exist, if not go to form.. in C# by v-jetan

v-jetan
Sun Oct 23 22:02:52 CDT 2005

Hi dewright_ca,

Is your problem resolved? If you have any concern, please feel free to tell
me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.