Feb 25th, 2004, 07:22 AM
#1
Thread Starter
Fanatic Member
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:
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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As _
Long
Const KEY_READ = &H20019
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
' Return True if a Registry key exists
Public Function CheckRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As Boolean
Dim handle As Long
' Try to open the key
If RegOpenKeyEx(hKey, KeyName, 0, KEY_READ, handle) = 0 Then
' The key exists
CheckRegistryKey = True
' Close it before exiting
RegCloseKey handle
End If
End Function
How can I check if the key actually exists???
Last edited by MikkyThomeon; Feb 26th, 2004 at 12:40 PM .
Feb 25th, 2004, 07:23 AM
#2
Thread Starter
Fanatic Member
BTW:
VB Code:
Private Sub Form_Load()
CheckRegistryKey HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MySQL Connector/ODBC 3.51"
End Sub
... this is how I was colling the function. Is that OK??
Feb 25th, 2004, 08:07 AM
#3
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.
Feb 25th, 2004, 09:27 AM
#4
Frenzied Member
Which means you need to check the RetVal
Feb 25th, 2004, 10:03 AM
#5
Frenzied Member
If you like, I can upload a reall good Registry Demo project.
Feb 25th, 2004, 01:10 PM
#6
Thread Starter
Fanatic Member
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:
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.
Feb 25th, 2004, 01:15 PM
#7
Frenzied Member
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
Feb 26th, 2004, 12:39 PM
#8
Thread Starter
Fanatic Member
Thanks Brian. This issue is resolved with a simple solution!!!
VB Code:
'---------------------------------------------------------------------------------------
' Procedure : IsDriverInstalled
' DateTime : 2004/02/25 12:48
' Author : Administrator
' Purpose : Checks if the uninstall key exists - this indicates that the
' MyODBC driver has been installed on the target system
'---------------------------------------------------------------------------------------
'
Function IsMyODBCInstalled() As Boolean
Dim hKey As Long
If RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MySQL Connector/ODBC 3.51", 0, 1, hKey) = ERROR_SUCCESS Then
IsMyODBCInstalled = True
RegCloseKey hKey
Else
IsMyODBCInstalled = False
End If
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
Forum Rules
Click Here to Expand Forum to Full Width