Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Check If Registry SubKey Exist Or Not.

Posted on 2006-11-05
16
Medium Priority
?
620 Views
Last Modified: 2008-01-09

I am trying to see if i can make something in VB that
can tell me if a SubKey in Registry does exist or not.

Dim strRegResult As String
Read = ReadRegistry
If "HKEY_CURRENT_USER\SOFTWARE\SubTest\" exist Then
MsgBox "It does exist"
Else
MsgBox "The SubKey does not exist"
End If

Sorry i just made all that up to give some small example of what i want.

Thanks
0
Comment
Question by:Zak-R
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
16 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17875912
I think you might want to use existing utility code like this (assuming vb6):
http://www.codetoad.com/vb_modify_registry.asp


0
 
LVL 2

Author Comment

by:Zak-R
ID: 17875922

Those two links are good,
But i just want to get the reading value of the SubKey.
Note that i don't want to read any Stream value of the Registry.

Take a look to this example:

Private Sub Form_Load()
Text1.Text = GetString(HKEY_CURRENT_USER, "Software\SubTest", "MyStreamValue")
End Sub

With this i can get the value of a Stream Key but not a the SubKey.
Get it ?



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Zak-R
ID: 17875938


=================================
Thanks angel, but the example in this page:
http://www.codetoad.com/vb_modify_registry.asp
does not have a solution, it does not work for me.
=================================

Note: I am not looking for a code to modefy the Registry,
I just  want my app to determine if the SubKey exist or not.

Thanks

0
 
LVL 29

Expert Comment

by:Nightman
ID: 17875997
In the example that I posted, add the cRegistry.cls as a class in your project.

Then:

Private Sub Form_Load()
  Dim oReg As cRegistry
  Set oReg = New cRegistry
  oReg.ClassKey = HKEY_CURRENT_USER
  oReg.SectionKey = "Software\SubTest"
  oReg.ValueKey = "MyStreamValue"
  Text1.Text = oReg.Value
End Sub

There is also a method called KeyExists - you can use this to test for the existence of a given key.
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17876010
obviously don't forget to set oReg=nothing at the end

Alternatively you could create the oReg class object at a modular level and keep it in memory throughout the lifespan of you application as well.
0
 
LVL 2

Author Comment

by:Zak-R
ID: 17876014

Hi Nightman

Read my comment again, I really apreciate you reply, but i mentioned
that i don't want to read the Stream Key from this path in the Registry.

*** I want to be able to get in the TextBox if the that SubKey exist or not. ***

Dim oReg As cRegistry
Set oReg = New cRegistry
oReg.ClassKey = HKEY_CURRENT_USER
oReg.SectionKey = "Software\SubTest"  <=== Just this SubKey
oReg.ValueKey = "MyStreamValue"        <=== But not this one
Text1.Text = oReg.Value

I will apreciate if you can help me with it

Thanks






0
 
LVL 29

Expert Comment

by:Nightman
ID: 17876020
Dim oReg As cRegistry
Set oReg = New cRegistry
oReg.ClassKey = HKEY_CURRENT_USER
oReg.SectionKey = "Software\SubTest"  <=== Just this SubKey
Text1.Text = CStr(oReg.KeyExists)

0
 
LVL 2

Author Comment

by:Zak-R
ID: 17876029

Yes, exactly just the SubFolder.


0
 
LVL 29

Expert Comment

by:Nightman
ID: 17876035
Try the code I just posted - it returns true or false to the textbox based on the existence of that folder.
0
 
LVL 2

Author Comment

by:Zak-R
ID: 17876039

Yeah, I been trying to get it to work, But it does not show any False or True in the TextBox.
0
 
LVL 29

Accepted Solution

by:
Nightman earned 200 total points
ID: 17876044
odd, it works for me.

Private Sub Form_Load()
  Dim oReg As cRegistry
  Set oReg = New cRegistry
  oReg.ClassKey = HKEY_CURRENT_USER
  oReg.SectionKey = "Software\SubTest"
  Text1.Text = CStr(oReg.KeyExists)
End Sub

Is there anything else that you might be doing to clear this value, or set it to something else?
0
 
LVL 2

Author Comment

by:Zak-R
ID: 17876045

Oh Yeah!, this time works : )
      Thanks Nightman.
This is now what i was looking for, but i think is good.

Thank you
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17876052
Remember, you can use that class to modify, add, delete, check for existence or enumerate values from the registry - pretty useful.
0
 
LVL 2

Author Comment

by:Zak-R
ID: 17876055

Also thank you for you help angelIII
0
 
LVL 2

Author Comment

by:Zak-R
ID: 17876057

Thanks Nightman, I'll play with it : )

Thank you
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question