Tools Links Login

Manage the Registry Module, Part 2

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

About this post

Posted: 2019-08-22
By: PatrickSeymour
Viewed: 349 times

Categories

Visual Basic 6

Attachments

regmodule2.zip
Posted: 8/22/2019 4:57:56 PM
Size: 8,382 bytes

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.