CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2000
    Posts
    69

    How to find right folder in the registry?

    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!


  2. #2
    Join Date
    Aug 2000
    Location
    Ottawa, Canada
    Posts
    469

    Re: How to find right folder in the registry?

    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!

  3. #3
    Join Date
    Feb 2000
    Location
    Illinois
    Posts
    37

    Re: How to find right folder in the registry?

    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





  4. #4
    Join Date
    Aug 2000
    Posts
    69

    Re: How to find right folder in the registry?

    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++


  5. #5
    Join Date
    Feb 2000
    Location
    Illinois
    Posts
    37

    Re: How to find right folder in the registry?

    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?


  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: How to find right folder in the registry?

    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

  7. #7
    Join Date
    Aug 2000
    Posts
    69

    Re: How to find right folder in the registry?

    Excelent!
    Thank you!


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

Featured