Results 1 to 11 of 11

Thread: Registry Folders.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    Hi I was wondering if someone could help me out with a code for the registry. Someone posted a code on here in another post about getting all the strings out of a particular registry folder, sorry I can't remember the name of who posted it. But I actually need something just to get the list of folders(or keys what ever you want to call them) out of that folder. could someone please help?

    thanx in advance.

  2. #2
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    Hi Crypt.

    I'm not 100% clear on what you want so I'll give a general
    answer here and send you a module that I use for
    Registry/Ini stuff separately.

    Code:
        'Set values for the variables:
        'strAppName, strSection, strKey
        'Use this to retrieve a value from the registry
        strResult = GetSetting(strAppName, strSection, strKey, "DefaultValueHere")
    
        'Use this to save a value to the registry
        strResult = SaveSetting(strAppName, strSection, strKey, strYourSetting)
    Hope this helps.

    JC

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    'Twas mine self!
    You can find it here along with many other Registry functions.

    Hope it helps.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    Hi SonGouki,

    thats a great code, but I can't work it out from your code how to enumerate all of the SubKeys I think as you put it.

    I just need all the sub folders in a certain key to be put into a listbox, SonGouki would be able to edit it and post it here? I'd really appreciate it.

  5. #5
    Lively Member
    Join Date
    May 1999
    Location
    India
    Posts
    97

    Thumbs up Getting registry folders

    Hiya,
    How familiar are u with using API in VB?? if u are take a look at the API RegEnumKey that does exxactly what u require... if not mail me n i'll try n get u some code...

    Cheers
    GauravM
    [email protected]
    " Programming today is a race between software-engineers striving to build bigger and
    better idiot-proof programs and the universe trying to produce bigger and better idiots.
    So far the universe is winning".
    :-)

  6. #6
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217

    Cool

    Alrighty, you asked for it! Here ya go:
    Code:
    '============================
    '=== GENERAL DECLARATIONS ===
    '============================
    
    '<<< OPTION STATEMENTS >>>
    Option Explicit
    
    
    '<<< CONSTANTS >>>
    'Variable maximum sizes.
    Private Const MAX_PATH As Integer = 260
    Private Const MAXBYTE As Integer = &HFF
    Private Const MAXCHAR As Integer = &H7F
    Private Const MAXSHORT As Integer = &H7FFF
    
    'Error codes.
    Private Const ERROR_SUCCESS As Long = 0
    Private Const ERROR_MORE_DATA As Long = 234
    
    
    '<<< ENUMERATIONS >>>
    'Top-level registry Keys.
    Private Enum eRegistryTopKeys
       HKEY_CLASSES_ROOT = &H80000000
       HKEY_CURRENT_USER = &H80000001
       HKEY_LOCAL_MACHINE = &H80000002
       HKEY_USERS = &H80000003
       HKEY_PERFORMANCE_DATA = &H80000004
       HKEY_CURRENT_CONFIG = &H80000005
       HKEY_DYN_DATA = &H80000006
    End Enum
    
    'Registry data types.
    Private Enum eRegistryDataTypes
       REG_NONE = 0
       REG_SZ = 1
       REG_EXPAND_SZ = 2
       REG_BINARY = 3
       REG_DWORD = 4
       REG_DWORD_LITTLE_ENDIAN = 4
       REG_DWORD_BIG_ENDIAN = 5
       REG_LINK = 6
       REG_MULTI_SZ = 7
       REG_RESOURCE_LIST = 8
       REG_FULL_RESOURCE_DESCRIPTOR = 9
       REG_RESOURCE_REQUIREMENTS_LIST = 10
    End Enum
    
    'Object security constants.
    Private Enum eSecurityRights
       READ_CONTROL = &H20000
       SYNCHRONIZE = &H100000
       SPECIFIC_RIGHTS_ALL = &HFFFF
       STANDARD_RIGHTS_REQUIRED = &HF0000
       STANDARD_RIGHTS_ALL = &H1F0000
       STANDARD_RIGHTS_READ = (READ_CONTROL)
       STANDARD_RIGHTS_WRITE = (READ_CONTROL)
    End Enum
    
    'Registry Key operation request flags.
    Private Enum eRegistryKeyOperations
       KEY_EVENT = &H1
       KEY_QUERY_VALUE = &H1
       KEY_SET_VALUE = &H2
       KEY_CREATE_SUB_KEY = &H4
       KEY_ENUMERATE_SUB_KEYS = &H8
       KEY_NOTIFY = &H10
       KEY_CREATE_LINK = &H20
       KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
       KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
       KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
       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))
    End Enum
    
    
    '<<< TYPE DEFINITIONS >>>
    Private Type FILETIME
            dwLowDateTime As Long
            dwHighDateTime As Long
    End Type
    
    '<<< DECLARES >>>
    Private Declare Function RegCloseKey _
                    Lib "advapi32.dll" _
                    (ByVal hKey As Long) As Long
    
    Private Declare Function RegOpenKeyEx _
                    Lib "advapi32.dll" _
                    Alias "RegOpenKeyExA" _
                    (ByVal hKey As eRegistryTopKeys, ByVal lpSubKey As String, _
                    ByVal ulOptions As Long, ByVal samDesired As eRegistryKeyOperations, _
                    phkResult As Long) As Long
    
    Private 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
    
    Private Declare Function RegEnumValue _
                    Lib "advapi32.dll" _
                    Alias "RegEnumValueA" _
                    (ByVal hKey As Long, ByVal dwIndex As Long, _
                    ByVal lpValueName As String, lpcbValueName As Long, _
                    ByVal lpReserved As Long, lpType As Long, _
                    lpData As Byte, lpcbData As Long) As Long
    
    Private Declare Function RegQueryInfoKey _
                    Lib "advapi32.dll" _
                    Alias "RegQueryInfoKeyA" _
                    (ByVal hKey As Long, ByVal lpClass As String, _
                    lpcbClass As Long, ByVal lpReserved As Long, _
                    lpcSubKeys As Long, lpcbMaxSubKeyLen As Long, _
                    lpcbMaxClassLen As Long, lpcValues As Long, _
                    lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, _
                    lpcbSecurityDescriptor As Long, lpftLastWriteTime As FILETIME) As Long
    
    
    '========================
    '=== EVENT PROCEDURES ===
    '========================
    
    Private Sub Form_Load()
       Call ListRegKeys(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion", True, True, True)
    End Sub
    
    Private Sub Form_Resize()
       List1.Left = 0
       List1.Top = 0
       List1.Width = Me.ScaleWidth
       List1.Height = Me.ScaleHeight
    End Sub
    
    
    '==========================
    '=== PRIVATE PROCEDURES ===
    '==========================
    
    Private Sub ListRegKeys( _
            hKey As eRegistryTopKeys, _
            sSubKey As String, _
            Optional bClearList As Boolean = True, _
            Optional bEnumValues As Boolean = False, _
            Optional bEnumSubKeys As Boolean = False, _
            Optional iRecursion As Integer = 0)
            
       Dim idx As Integer
       Dim lRet As Long
       Dim hRegKey As Long
       Dim sKey As String
       Dim lKey As Long
       Dim sClass As String
       Dim lClass As Long
       Dim udtModificationTime As FILETIME
       
       lRet = RegOpenKeyEx(hKey, sSubKey, 0, KEY_READ, hRegKey)
              
       If lRet = ERROR_SUCCESS Then
          
          If bClearList = True Then
             Call List1.Clear
          End If
          
          Do
             sKey = String(MAX_PATH, 0)
             lKey = Len(sKey) - 1
             sClass = String(MAX_PATH, 0)
             lClass = Len(sClass) - 1
             lRet = RegEnumKeyEx(hRegKey, idx, sKey, lKey, 0, sClass, lClass, udtModificationTime)
             
             If lRet = ERROR_SUCCESS Then
                idx = idx + 1
                
                If lKey > 0 Then
                   sKey = Left(sKey, lKey)
                   Call List1.AddItem(String(iRecursion, ">") & sKey)
                   
                   If bEnumValues = True Then
                      Call ListRegValues(hRegKey, sKey, False, iRecursion + 1)
                   End If
                   
                   If bEnumSubKeys = True Then
                      Call ListRegKeys(hRegKey, sKey, False, bEnumValues, True, iRecursion + 1)
                   End If
                End If
                
             End If
                
          Loop While lRet = ERROR_SUCCESS
          
          Call RegCloseKey(hRegKey)
       End If
    End Sub
    
    Private Sub ListRegValues( _
            hKey As eRegistryTopKeys, _
            sSubKey As String, _
            Optional bClearList As Boolean = True, _
            Optional iIndent As Integer = 0)
            
       Dim lRet As Long
       Dim hRegKey As Long
       Dim sClass As String
       Dim lClass As Long
       Dim lNumSubKeys As Long
       Dim lMaxSubKeyLen As Long
       Dim lMaxClassLen As Long
       Dim lNumValues As Long
       Dim lMaxValueNameLen As Long
       Dim lMaxValueDataLen As Long
       Dim lSecurityDescriptorLen As Long
       Dim udtModificationTime As FILETIME
       Dim idx As Integer
       Dim sValueName As String
       Dim lNameLen As Long
       Dim bytValueData() As Byte
       Dim lDataLen As Long
       Dim lDataType As Long
       
       lRet = RegOpenKeyEx(hKey, sSubKey, 0, KEY_READ, hRegKey)
              
       If lRet = ERROR_SUCCESS Then
          sClass = String(MAX_PATH, 0)
          lClass = Len(sClass) - 1
          lRet = RegQueryInfoKey(hRegKey, sClass, lClass, 0, lNumSubKeys, lMaxSubKeyLen, _
                 lMaxClassLen, lNumValues, lMaxValueNameLen, lMaxValueDataLen, _
                 lSecurityDescriptorLen, udtModificationTime)
          
          If lRet = ERROR_SUCCESS Then
             
             If bClearList = True Then
                Call List1.Clear
             End If
             
             ReDim bytValueData(lMaxValueDataLen + 1)
             
             For idx = 0 To lNumValues - 1 Step 1
                lNameLen = lMaxValueNameLen + 1
                sValueName = String(lNameLen, 0)
                lDataLen = lMaxValueDataLen + 1
                lRet = RegEnumValue(hRegKey, idx, sValueName, lNameLen, 0, _
                       lDataType, bytValueData(0), lDataLen)
                
                If lRet = ERROR_SUCCESS _
                And lDataType = REG_SZ Then
                   
                   If lDataLen > 0 Then
                      lDataLen = lDataLen - 1
                   End If
                   
                   Call List1.AddItem(Space(iIndent) & Left(sValueName, lNameLen) & " = " & _
                                      Left(StrConv(bytValueData, vbUnicode), lDataLen))
                End If
                
             Next idx
             
          End If
          
          Call RegCloseKey(hRegKey)
       End If
    End Sub
    Like before, paste all of this code as is into a Form. The Form must have a ListBox on it named List1.
    I made this code as pliable as I could so that it will do a number of Registry listing functions (except for the previously mentioned handling of Registry data-types other that the SZ string type).

    If you want a listing of all Values in a Key then do the following:
    Code:
    Call ListRegValues(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folder", True)
    Where the hKey parameter is the name of the top-level Key that contains the SubKey you wish to query, the sSubKey is the full path from the top-level Key of the Key you actually want the info on.

    If you want a listing of all the "Folders" (ie. Registry SubKeys of a Key) then call the ListRegKeys as follows:
    Code:
    Call ListRegKeys(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion", True)
    If you want to list all the Values of all the SubKeys in a Key then do the following:
    Code:
    Call ListRegKeys(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion", True, True)
    If you want a list of the SubKeys heirarchy from a Key then do the following:
    Code:
    Call ListRegKeys(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion", True, , True)
    If you want a list of the SubKeys heirarchy and all of their Values from a Key then do the following:
    Code:
    Call ListRegKeys(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion", True, True, True)

    Hope that this clears up all your questions. If you need me to elaborate on any of this then don't be afraid to ask, I'm always glad to help!

    Later.

  7. #7
    Addicted Member
    Join Date
    Jan 2000
    Location
    Oshkosh, WI
    Posts
    163
    Microsoft published an dll named regobj that presents the registry as an object tree. You should be able to find it on their visual studio download area.

  8. #8
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217

    Talking

    Just floating this thread back up to the top in case you didn't see it Crypt, 'cause you never replied.
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

  9. #9
    Guest
    Code:
    ' -----------------
    ' ADVAPI32
    ' -----------------
    ' function prototypes, constants, and type definitions
    ' for Windows 32-bit Registry API
    
    Dim YourScore As Integer
    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
    
    ' Registry API prototypes
    
    Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
    Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    'Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
    Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hkey As Long, ByVal lpSubKey As String) As Long
    Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hkey As Long, ByVal lpValueName As String) As Long
    Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hkey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName 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 RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hkey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
    Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
    'Declare Function RegGetKeySecurity Lib "advapi32.dll" (ByVal hKey As Long, ByVal SecurityInformation As Long, pSecurityDescriptor As SECURITY_DESCRIPTOR, lpcbSecurityDescriptor As Long) As Long
    Declare Function RegLoadKey Lib "advapi32.dll" Alias "RegLoadKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal lpFile As String) As Long
    Declare Function RegNotifyChangeKeyValue Lib "advapi32.dll" (ByVal hkey As Long, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long, ByVal hEvent As Long, ByVal fAsynchronus As Long) As Long
    Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    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 RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyA" (ByVal hKey As Long, ByVal lpClass As String, lpcbClass As Long, lpReserved As Long, lpcSubKeys As Long, lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long, lpftLastWriteTime As FILETIME) As Long
    Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
    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
    Declare Function RegReplaceKey Lib "advapi32.dll" Alias "RegReplaceKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal lpNewFile As String, ByVal lpOldFile As String) As Long
    Declare Function RegRestoreKey Lib "advapi32.dll" Alias "RegRestoreKeyA" (ByVal hkey As Long, ByVal lpFile As String, ByVal dwFlags As Long) As Long
    'Declare Function RegSaveKey Lib "advapi32.dll" Alias "RegSaveKeyA" (ByVal hKey As Long, ByVal lpFile As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
    'Declare Function RegSetKeySecurity Lib "advapi32.dll" (ByVal hKey As Long, ByVal SecurityInformation As Long, pSecurityDescriptor As SECURITY_DESCRIPTOR) As Long
    Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
    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
    Declare Function RegUnLoadKey Lib "advapi32.dll" Alias "RegUnLoadKeyA" (ByVal hkey As Long, ByVal lpSubKey As String) As Long
    
    Public Const REG_NONE = 0                       ' No value type
    Public Const REG_SZ = 1                         ' Unicode nul terminated string
    Public Const REG_EXPAND_SZ = 2                  ' Unicode nul terminated string
    Public Const REG_BINARY = 3                     ' Free form binary
    Public Const REG_DWORD = 4                      ' 32-bit number
    Public Const REG_DWORD_LITTLE_ENDIAN = 4        ' 32-bit number (same as REG_DWORD)
    Public Const REG_DWORD_BIG_ENDIAN = 5           ' 32-bit number
    Public Const REG_LINK = 6                       ' Symbolic Link (unicode)
    Public Const REG_MULTI_SZ = 7                   ' Multiple Unicode strings
    Public Const REG_RESOURCE_LIST = 8              ' Resource list in the resource map
    Public Const REG_FULL_RESOURCE_DESCRIPTOR = 9   ' Resource list in the hardware description
    Public Const REG_RESOURCE_REQUIREMENTS_LIST = 10
    Public Const REG_CREATED_NEW_KEY = &H1                      ' New Registry Key created
    Public Const REG_OPENED_EXISTING_KEY = &H2                      ' Existing Key opened
    Public Const REG_WHOLE_HIVE_VOLATILE = &H1                      ' Restore whole hive volatile
    Public Const REG_REFRESH_HIVE = &H2                      ' Unwind changes to last flush
    Public Const REG_NOTIFY_CHANGE_NAME = &H1                      ' Create or delete (child)
    Public Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
    Public Const REG_NOTIFY_CHANGE_LAST_SET = &H4                      ' Time stamp
    Public Const REG_NOTIFY_CHANGE_SECURITY = &H8
    Public Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME Or REG_NOTIFY_CHANGE_ATTRIBUTES Or REG_NOTIFY_CHANGE_LAST_SET Or REG_NOTIFY_CHANGE_SECURITY)
    'Public Const REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE)
    
    ' Reg Create Type Values...
    Public Const REG_OPTION_RESERVED = 0           ' Parameter is reserved
    Public Const REG_OPTION_NON_VOLATILE = 0       ' Key is preserved when system is rebooted
    Public Const REG_OPTION_VOLATILE = 1           ' Key is not preserved when system is rebooted
    Public Const REG_OPTION_CREATE_LINK = 2        ' Created key is a symbolic link
    Public Const REG_OPTION_BACKUP_RESTORE = 4     ' open for backup or restore
    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 DELETE = &H10000
    Public Const READ_CONTROL = &H20000
    Public Const WRITE_DAC = &H40000
    Public Const WRITE_OWNER = &H80000
    Public Const SYNCHRONIZE = &H100000
    
    ' Reg Key Security Options
    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 Sub savekey(hkey As Long, strpath As String)
    Dim keyhand&
    r = RegCreateKey(hkey, strpath, keyhand&)
    r = RegCloseKey(keyhand&)
    End Sub
    
    Function RegQueryStringValue(ByVal hkey As Long, ByVal strValueName As String)
        Dim lResult As Long
        Dim lValueType As Long
        Dim strBuf As String
        Dim lDataBufSize As Long
        
        On Error GoTo 0
        lResult = RegQueryValueEx(hkey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
        If lResult = ERROR_SUCCESS Then
            If lValueType = REG_SZ Then
                strBuf = String(lDataBufSize, " ")
                lResult = RegQueryValueEx(hkey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
                If lResult = ERROR_SUCCESS Then
                    RegQueryStringValue = StripTerminator(strBuf)
                End If
            End If
        End If
    End Function
    
    Public Function getstring(hkey As Long, strpath As String, strvalue As String)
    'This module allows easy access to the Windows 95 and NT Registry.
    'It takes the following parameters:
    '
    'HKEY - one of the following constants:
    'HKEY_CLASSES_ROOT
    'HKEY_CURRENT_USER
    'HKEY_LOCAL_MACHINE
    'HKEY_USERS
    'HKEY_PERFORMANCE_DATA
    '
    'strpath - the rest of the registry 'path' eg:
    '"Control Panel\desktop"
    '
    'strvalue - A string that refers to the key that you want to retrieve eg:
    '"Wallpaper"
    '
    'The Example above would be called as follows:
    '
    'dim strwallpaper as string
    'strwallpaper = getstring(HKEY_CURRENT_USER, "Control Panel\desktop", "Wallpaper")
    '
    'This would return the current desktop wallpaper
    '
    'This module downloaded from VB-World at http://www.geocities.com/SiliconValley/Bay/8409/
    
    
    Dim keyhand&
    Dim datatype&
    r = RegOpenKey(hkey, strpath, keyhand&)
    getstring = RegQueryStringValue(keyhand&, strvalue)
    r = RegCloseKey(keyhand&)
    End Function
    
    Function StripTerminator(ByVal strString As String) As String
        Dim intZeroPos As Integer
    
        intZeroPos = InStr(strString, Chr$(0))
        If intZeroPos > 0 Then
            StripTerminator = Left$(strString, intZeroPos - 1)
        Else
            StripTerminator = strString
        End If
    End Function
    
    Public Sub savestring(hkey As Long, strpath As String, strvalue As String, strdata As String)
    'This module allows easy access to the Windows 95 and NT Registry.
    'It takes the following parameters:
    '
    'HKEY - one of the following constants:
    'HKEY_CLASSES_ROOT
    'HKEY_CURRENT_USER
    'HKEY_LOCAL_MACHINE
    'HKEY_USERS
    'HKEY_PERFORMANCE_DATA
    '
    'strpath - the rest of the registry 'path' eg:
    '"Control Panel\desktop"
    '
    'strvalue - A string that refers to the key that you want to save eg:
    '"Wallpaper"
    '
    'strdata - the string you want to save against strvalue eg:
    '"c:\windows\clouds.bmp"
    '
    'The Example above would be called as follows:
    '
    'dim strwallpaper as string
    'call savestring(HKEY_CURRENT_USER, "Control Panel\desktop", "Wallpaper", "C:\Windows\Clouds.bmp")
    '
    'If this 'path' does not exist, it will be created.
    '
    'This module downloaded from VB-World at http://www.geocities.com/SiliconValley/Bay/8409/
    
    
    Dim keyhand&
    r = RegCreateKey(hkey, strpath, keyhand&)
    r = RegSetValueEx(keyhand&, strvalue, 0, REG_SZ, ByVal strdata, Len(strdata))
    r = RegCloseKey(keyhand&)
    End Sub

  10. #10
    Guest
    To use the above exaple...

    To save info
    Call savstring(HKEY_CURRENT_USER, "Software\MpApp","DisplayMessage","On")
    Call Savestring(HKEY, Path, Value, Data)

    To get info
    Info = getstring(HKEY_CURRENT_USER, "Software\MpApp","DisplayMessage")
    Variable = getstring(HKEY, Path, Value)


  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215

    Thanx SonGouki

    Thanx SonGouki awesome code, yeah the topic had slipped past me, thanx for bringing it back up to the top.

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