Click to See Complete Forum and Search --> : How to find right folder in the registry?


AlexKrat
November 21st, 2000, 10:45 AM
I need to set a value in the registry.
The root key is SOFTWARE\Microsoft\Jet
I don't know in advance what version of the jet is instaled so I would like to search in this directory.
But How?

Thank you!

Andrew R.
November 21st, 2000, 10:53 AM
There are could be only several differen SubKey in Jet (e.g. "3.5" and "4.0"). So, it would be easier to check them one by one.

___________________
If you like it - rate it!

strelzyks
November 21st, 2000, 03:57 PM
You would need to enumerate all of the subkeys to check them. Use the API RegEnumKeyEx, the prototype is included below, and you can check MSDN for syntax.

public Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (byval hKey as Long, byval dwIndex as Long, byval lpName as string, lpcbName as Long, byval lpReserved as Long, byval lpClass as string, lpcbClass as Long, lpftLastWriteTime as FILETIME) as Long

AlexKrat
November 22nd, 2000, 07:38 PM
Thank you for your reply!
Maybe I did something wrong but It only returned the string values int the root directory and not
the subfolders.
I used MSDN example for C++

strelzyks
November 27th, 2000, 11:51 AM
Send me the code you used. I am looking in MSDN from April 2000. Did you use the MSDN library from Visual Studio or the MSDN that Microsoft puts into its subscriptions?

John G Duffy
November 27th, 2000, 01:11 PM
Having trouble getting this reply accepted. This is try # 3
Start a new project. Add a command button to the form
Add a Module and paste the following code to the module
'
Option Explicit

Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_READ = &H20000
Public Const STANDARD_RIGHTS_WRITE = &H20000
Public Const STANDARD_RIGHTS_EXECUTE = &H20000
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or _
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) _
And (Not SYNCHRONIZE))
Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or _
KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Public Const KEY_EXECUTE = (KEY_READ)
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Public Const ERROR_SUCCESS = 0&


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
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" _
(ByVal hKey As Long, ByVal dwIndex As Long, ByVal _
lpname As String, lpcbName As Long, _
ByVal lpReserved As Long, _
ByVal lpClass As String, _
lpcbClass As Long, _
lpftLastWriteTime As FILETIME) As Long
Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long

Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
'
' end of Module code
'
'
'
Paste the following code into the general declarations section of the Form.
'
Option Explicit

Private Sub Command1_Click()
MsgBox DoesKeyExist(HKEY_LOCAL_MACHINE, "Software\Microsoft\Jet")
Unload Me
End Sub

Private Function DoesKeyExist(Root As Long, Key As String)
Dim ft As FILETIME
Dim keyhandle&
Dim res&
Dim curidx&
Dim keyname$, classname$
Dim keylen&, classlen&
Dim msg$
Dim reserved&
res& = RegOpenKeyEx(Root, Key, 0, KEY_READ, keyhandle)
If res <> ERROR_SUCCESS Then
MsgBox "Can't open key"
Exit Function
End If
Do
keylen& = 2000
classlen& = 2000
keyname$ = String$(keylen, 0)
classname$ = String$(classlen, 0)
res = RegEnumKeyEx(keyhandle, curidx, keyname$, keylen, reserved, classname$, classlen, ft)
curidx = curidx + 1
If res = ERROR_SUCCESS Then msg$ = msg$ & Left$(keyname$, keylen) + vbCrLf
Loop While res = ERROR_SUCCESS

Call RegCloseKey(keyhandle)
DoesKeyExist = msg$
End Function
'
'
'
Run the program and click the button

John G

AlexKrat
November 27th, 2000, 07:22 PM
Excelent!
Thank you!