Solved

How to read a registry entry

Posted on 2006-11-03
14
501 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ms access #TYPE! error on report when no data 4 77
VBA saving file message display 5 67
passing a value with stream reader AFTER a ";" 3 67
RUNRMTCMD from AS/400 12 47
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

803 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