Here is another take on registry management. See the attached ZIP file for the source code.
Usage
Public Function GetShellFolder(sFolder As String) As String
' handle of the registry key to be accessed
Dim hKey As Long
' path of the folder being sought (returned by function)
Dim sFolderName As String
' path of the Shell Folders key in the registry
Dim sShellFoldersPath As String
' define the Shell Folders path
sShellFoldersPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
' attempt to open the key; on failure, exit the function
If (OpenKey(HKCU, sShellFoldersPath, hKey, vbNullString, NOT_USED, KEY_READ, NOT_USED)) <> SUCCESS Then Exit Function
' declare a buffer large enough to hold the data being accessed
sFolderName = Space(255)
' query the registry for the desired value
GetStringValue hKey, sFolder, sFolderName
' close the key
CloseKey hKey
' trim the spaces from the left and right of the path value
sFolderName = Trim(sFolderName)
' remove the null character from the end of the string
sFolderName = Left(sFolderName, Len(sFolderName) - 1)
'if there is a backslash on the end of the path, remove it
If Right(sFolderName, 1) = "\" Then sFolderName = Left(sFolderName, Len(sFolderName) - 1)
' return the value found in the registry
GetShellFolder = sFolderName
End Function
Attachments
File | Uploaded | Size |
---|---|---|
969-20190822-165756-regmodule2.zip | 8/22/2019 4:57:56 PM | 8382 |