Results 1 to 8 of 8

Thread: Registry key Exists [Resolved]

  1. #1

    Thread Starter
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648

    Registry key Exists [Resolved]

    I have searched the other posts but they do not work for this key:


    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MySQL Connector/ODBC 3.51


    I have tried using this code:

    VB Code:
    1. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
    2.     (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
    3.     ByVal samDesired As Long, phkResult As Long) As Long
    4.  
    5. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As _
    6.     Long
    7.    
    8. Const KEY_READ = &H20019
    9. Const HKEY_CLASSES_ROOT = &H80000000
    10. Const HKEY_CURRENT_CONFIG = &H80000005
    11. Const HKEY_CURRENT_USER = &H80000001
    12. Const HKEY_LOCAL_MACHINE = &H80000002
    13. Const HKEY_USERS = &H80000003
    14.  
    15. ' Return True if a Registry key exists
    16.  
    17. Public Function CheckRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As Boolean
    18.     Dim handle As Long
    19.     ' Try to open the key
    20.     If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) = 0 Then
    21.         ' The key exists
    22.         CheckRegistryKey = True
    23.         ' Close it before exiting
    24.         RegCloseKey handle
    25.     End If
    26. End Function


    How can I check if the key actually exists???
    Last edited by MikkyThomeon; Feb 26th, 2004 at 12:40 PM.

  2. #2

    Thread Starter
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    BTW:

    VB Code:
    1. Private Sub Form_Load()
    2.     CheckRegistryKey HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MySQL Connector/ODBC 3.51"
    3. End Sub

    ... this is how I was colling the function. Is that OK??

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    From the API-Guide regarding the RegOpenKeyEx :

    If the function succeeds, the return value is ERROR_SUCCESS.

    If the function fails, the return value is a nonzero error code defined in WINERROR.H. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Which means you need to check the RetVal

  5. #5
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    If you like, I can upload a reall good Registry Demo project.

  6. #6

    Thread Starter
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    Please Brian - I would be really grateful! Sorry I took a while. Went home to eat, shower and (sleep!!!) a bit before tackling this again.

    I also checked out the API Guide and I am checking for Retval = 0

    VB Code:
    1. If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) = 0 Then


    The value for the constatnt ERROR_SUCCESS is zero

    Public Const ERROR_SUCCESS = 0&

    Thanks once again mate.

  7. #7
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Not sure if you can do that, but not sure. I normally use :

    RetVal = RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle)

    But here is the Registry Project for you to check out.
    Attached Files Attached Files

  8. #8

    Thread Starter
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    Thanks Brian. This issue is resolved with a simple solution!!!


    VB Code:
    1. '---------------------------------------------------------------------------------------
    2. ' Procedure : IsDriverInstalled
    3. ' DateTime  : 2004/02/25 12:48
    4. ' Author    : Administrator
    5. ' Purpose   : Checks if the uninstall key exists - this indicates that the
    6. '             MyODBC driver has been installed on the target system
    7. '---------------------------------------------------------------------------------------
    8. '
    9. Function IsMyODBCInstalled() As Boolean
    10.     Dim hKey As Long
    11.     If RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MySQL Connector/ODBC 3.51", 0, 1, hKey) = ERROR_SUCCESS Then
    12.         IsMyODBCInstalled = True
    13.         RegCloseKey hKey
    14.     Else
    15.         IsMyODBCInstalled = False
    16.     End If
    17. End Function

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