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

x
?
Solved

How to read a registry entry

Posted on 2006-11-03
14
Medium Priority
?
525 Views
Last Modified: 2013-12-26
Hi Experts,

I have a registry enter under HKEY_LOCAL_MACHINE\software\stockcontrol and I want to read the DBPath parameter. How do I do this please?

Many Thanks
Lee
0
Comment
Question by:ljhodgett
[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
  • 5
  • 3
  • 3
  • +3
14 Comments
 
LVL 2

Expert Comment

by:Elite_Bigfoot
ID: 17865121
Dim myReg As New Registry, KeyFound As Boolean
Dim HasIE As Boolean, sValue As String
sValue = ""
KeyFound = myReg.GetKeyValue(HKEY_LOCAL_MACHINE\software\stockcontrol, "Path", sValue)

If KeyFound Then HasIE = (sValue <> "")
If HasIE Then MsgBox(sValue)

Set myReg = Nothing
0
 
LVL 2

Expert Comment

by:Elite_Bigfoot
ID: 17865126
also add refrence to RegObj.dll library.
0
 

Author Comment

by:ljhodgett
ID: 17865303
Hi,

Elite Bigfoot.

When you say add reference regobj.dll do you mean in the components dialog or a line of code.

Many Thanks
Lee
0
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.

 
LVL 2

Expert Comment

by:Elite_Bigfoot
ID: 17865329
components/refrence dialog
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 17865369
Hi ljhodgett ,

you can download RegObj.dll
from the 'MVPS.ORG'  Controls and Components site here :

http://vb.mvps.org/tools/ControlsAndComponents.asp

There are two files :

RegObjI.exe (168 kB)
and
RegObjA.exe

0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 17865449
Add a Reference in your Ide.
VB-IDE \ Project \ References \ ---> press "Browse" button

filename : C:\WINDOWS\Desktop\RegObj\REGOBJ.DLL



Private Sub Form_Load()
 
 Dim key As RegKey
    Dim val As RegValue
    Set key = RegKeyFromString("\HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers")
    For Each val In key.Values
        MsgBox val.Name
    Next
   
End Sub
0
 

Author Comment

by:ljhodgett
ID: 17865830
Hi VB_Elmer,

The code works great thank you. The only issue, how do I read a certain parameter as: -

 For Each val In key.Values
        MsgBox val.Name
    Next

shows all the parameters and values in that registry. I.e. I would like to read a parameter called DBData

Many Thanks
Lee
0
 
LVL 2

Expert Comment

by:Elite_Bigfoot
ID: 17865839
Doesn't my above solution work?
0
 

Author Comment

by:ljhodgett
ID: 17865897
Hi Elite_Bigfoot.

I get the error on line: -

KeyFound = myReg.GetKeyValue(HKEY_LOCAL_MACHINE \ software \ stockcontrol, "Path", sValue)

method or data value not found and highlights getkey value. I have referenced the dll

Cheers
Lee
0
 
LVL 2

Expert Comment

by:Elite_Bigfoot
ID: 17865924
try replacing
Dim myReg As New Registry, KeyFound As Boolean

with the following two lines:

Dim myReg As New RegObj.RegistryClass()
Dim KeyFound As Boolean
0
 
LVL 13

Expert Comment

by:jmundsack
ID: 17865925
I don't want any points for this, but I just wanted you to know that you can do this entirely through code, without introducing a dependent object to the project.  There are many examples of this on the Internet, but the best one I've found is here:

http://vbaccelerator.com/home/VB/Code/Libraries/Registry_and_Ini_Files/Complete_Registry_Control/article.asp

HTH-Jon
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 17866010
>>Hi VB_Elmer,
>>i would like to read a parameter called DBData



instead...

    For Each val In key.Values
        MsgBox val.Name
    Next

...try this :

For Each val In key.Values
    If val.Name = "DBData" Then
        MsgBox val.Name & vbCrLf & val.Value
    End If
Next
0
 
LVL 35

Accepted Solution

by:
mvidas earned 1000 total points
ID: 17866261
Lee,

You can also use the same code you're using to create the registry entries, from http:Q_22046683.html#17858994

Just as you're using this to create/write to the registry:
 RegWrite "Software\Stock_control", "DBPath", "testdata", HKEY_LOCAL_MACHINE

The code I posted also includes a RegRead function:
 RegRead "Software\Stock_control", "DBPath", HKEY_LOCAL_MACHINE

Matt
0
 
LVL 28

Expert Comment

by:Ark
ID: 17871121
Private Sub Command1_Click()
   Dim wshShell, sDBPath
   Set wshShell = CreateObject("WScript.Shell")
   sDBPath = wshShell.RegRead("HKLM\software\stockcontrol\DBPath")
   MsgBox sDBPath
   Set wshShell = Nothing
End Sub
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
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