Solved

How to read a registry entry

Posted on 2006-11-03
14
507 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
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!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

717 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