if key exists

Talk2Tom11
08-04-2004, 08:24 PM
I made an if statement, and what I want it to do is check if a key in the registry is present, if it is open one form, if it isn't open the other form... I have placed my code below... my problem is that it will open up form2 no matter if the key is there or not... it never opens form3. If someones see's something wrong with this code please post to help.

MyKey = Registry.CurrentUser.OpenSubKey("User", False)
If (MyKey Is Nothing) Then
Dim f2 As New Form2
f2.ShowDialog()
Else
Dim f3 As New Form3
f3.ShowDialog()

MKoslof
08-04-2004, 08:33 PM
I assume this means the condition is always returning as nothing...so it always opens form2. Make sure you defined your objects correctly:



Dim oReg As Microsoft.Win32.Registry
Dim oRegKey As Microsoft.Win32.RegistryKey

oRegKey = oReg.CurrentUser.OpenSubKey("Software\\MK\\ThisOne", False)

If oRegKey Is Nothing Then
Dim f2 As New Form2
f2.ShowDialog()
Else
Dim f3 As New Form3
f3.ShowDialog()
End If

Talk2Tom11
08-04-2004, 09:04 PM
I defined it like this

Dim MyKey as registrykey = registry.currentuser.createsubkey ("NewKey")

MKoslof
08-05-2004, 06:02 AM
Currently, this key is probably not even created, hence this always returns nothing.

I assume you are trying to do something like this:



Dim RegKey As RegistryKey =Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\FakeKey\Fake2")

RegKey.CreateSubKey("MKoslof")




before creating the subKey do you open the parent or existing sub key that you want to add to?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum