Solved

How to read a registry entry

Posted on 2006-11-03
14
492 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
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 27

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now