Manage the Registry Module, Part 2

By | 2019-08-22

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

FileUploadedSize
969-20190822-165756-regmodule2.zip8/22/2019 4:57:56 PM8382
Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.