Solved

How to read a registry entry

Posted on 2006-11-03
14
505 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
Independent Software Vendors: 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

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 250 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

733 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