Results 1 to 3 of 3

Thread: Registery API

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    5

    Post

    When I use the SaveSettings function my string gets registered under the HKEY_LOCAL_USERS path. However I want to save the string in the HKEY_LOCAL_MACHINE\SOFTWARE path
    HELP !!!!!

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use the Registry API to write your own functions for Saving Data anywhere within the Registry, ie.
    Code:
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    
    Private Sub Command1_Click()
        Call SaveRegSetting("Software\Aaron Young", "MyValue", "Anything")
        Caption = GetRegSetting("Software\Aaron Young", "MyValue")
    End Sub
    
    Private Sub SaveRegSetting(ByVal sSubKey As String, ByVal sValue As String, ByVal sData As String)
        Dim lRegKey As Long
        
        If RegCreateKey(HKEY_LOCAL_MACHINE, sSubKey, lRegKey) = 0 Then
            Call RegSetValueEx(lRegKey, sValue, 0&, 1, ByVal sData, Len(sData))
            Call RegCloseKey(lRegKey)
        End If
    End Sub
    
    Private Function GetRegSetting(ByVal sSubKey As String, ByVal sValue As String) As String
        Dim lRegKey As Long
        Dim sData As String
        
        If RegOpenKey(HKEY_LOCAL_MACHINE, sSubKey, lRegKey) = 0 Then
            sData = Space$(255)
            Call RegQueryValueEx(lRegKey, sValue, 0&, 1, ByVal sData, 255)
            If InStr(sData, Chr(0)) Then
                sData = Left$(sData, InStr(sData, Chr(0)) - 1)
            End If
            GetRegSetting = sData
            Call RegCloseKey(lRegKey)
        End If
    End Function

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    5

    Post

    THANKS !!!!!
    OK...What about if I need to get a string from a table in a database. I also need to put the code in a module not a form.????

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