Results 1 to 2 of 2

Thread: win api to see if a reg key exsists

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Posts
    16

    win api to see if a reg key exsists

    Hi all,

    All I want to do is check to see if a key exsists and if so just return a boolean value. for example.

    HKey_LOCAL_MACHINE
    software\microsoft\visualbasic\6.0\

    if this is there return true.

    I think I have to use RegOpenKeyEx in api but not sure on how to do it. If some one can provide an example I would apprecaite it.

    thanks for you help

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    VB Code:
    1. Public Enum RegBaseKey
    2.     HKEY_CLASSES_ROOT = &H80000000
    3.     HKEY_CURRENT_USER = &H80000001
    4.     HKEY_LOCAL_MACHINE = &H80000002
    5.     HKEY_USERS = &H80000003
    6.     HKEY_CURRENT_CONFIG = &H80000005
    7.     HKEY_DYN_DATA = &H80000006
    8. End Enum
    9.  
    10. Private Const SYNCHRONIZE = &H100000
    11. Private Const READ_CONTROL = &H20000
    12. Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
    13. Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
    14. Private Const STANDARD_RIGHTS_ALL = &H1F0000
    15. Private Const KEY_QUERY_VALUE = &H1
    16. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    17. Private Const KEY_NOTIFY = &H10
    18. Private Const KEY_SET_VALUE = &H2
    19. Private Const KEY_CREATE_SUB_KEY = &H4
    20.  
    21. Private Const KEY_READ = ((READ_CONTROL Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
    22.  
    23. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
    24.  
    25. Public Function RegKeyExists(ByVal hKey As RegBaseKey, ByVal sKeyPath As String) As Boolean
    26.    
    27.     Dim hCurKey&
    28.     RegKeyExists = (RegOpenKeyEx(hKey, sKeyPath, 0, KEY_READ, hCurKey) = 0)
    29.    
    30. End Function


    Usage:
    Make sure you don't include trailing "\"
    VB Code:
    1. Private Sub Command1_Click()
    2. MsgBox RegKeyExists(HKEY_LOCAL_MACHINE, "software\NuWare")
    3. End Sub
    Last edited by Nucleus; Jul 12th, 2001 at 01:18 AM.

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