Results 1 to 7 of 7

Thread: Reading a registry key from the windows registry

  1. #1

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    Reading a registry key from the windows registry

    How do I go about reading the info held in a registry key using VB and input it into a text box?
    Thanks,
    - Gabe
    What are the dangerous of this? If any...

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    There is this from MSDN :

    GetSetting
    Returns a key setting value from an application's entry in the Windowsregistry.

    Syntax

    GetSetting(appname, section, key[, default])

    The GetSetting function syntax has thesenamed arguments:

    Part Description
    appname Required.String expression containing the name of the application or project whose key setting is requested.
    section Required. String expression containing the name of the section where the key setting is found.
    key Required. String expression containing the name of the key setting to return.
    default Optional.Expression containing the value to return if no value is set in the key setting. If omitted, default is assumed to be a zero-length string ("").


    Remarks

    If any of the items named in the GetSetting arguments do not exist, GetSetting returns the value of default.


    And then there's Hack's take on it :

    VB Code:
    1. Private Const HKEY_CURRENT_USER = &H80000001
    2.  
    3. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    4. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    5. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    6.  
    7. Private Sub Command1_Click()
    8. Dim Result As Long
    9. Dim KeyRet As Long
    10. Dim KeyToRead As String
    11. Dim KeyValue As String
    12. Dim Length As Long
    13. Result = RegOpenKey(HKEY_CURRENT_USER, "Software\New stuff\", KeyRet)
    14. KeyToRead = "demo"
    15. Result = RegQueryValueEx(KeyRet, KeyToRead, 0, 0, "", Length)
    16. KeyValue = Space$(Length - 1)
    17. Result = RegQueryValueEx(KeyRet, KeyToRead, 0, 0, ByVal KeyValue, Length)
    18. MsgBox KeyValue
    19. RegCloseKey KeyRet
    20. End Sub
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Those are two ways of doing almost the same. SaveSetting and GetSetting won't let you use a personal path, but it will always use the "HKCU\Software\VB and VBA Program Settings"
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by Mc Brain
    Those are two ways of doing almost the same. SaveSetting and GetSetting won't let you use a personal path, but it will always use the "HKCU\Software\VB and VBA Program Settings"
    Thats why I gave him both options...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I know!! I was explaining him the difference between the two approachs.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by Mc Brain
    I know!! I was explaining him the difference between the two approachs.
    Applause...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Well

    Originally posted by James Stanich
    Applause...
    Thank you, thank you.... but I'm too humble to say that I deserve them
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width