Determine whether a folder is shared

Determine whether a folder is shared

The Windows shell provides a simple way to detect whether a given folder is shared or not. You must call the SHGetFileInfo() API function and analyze the way it fills out a given structure.

Type SHFILEINFO    hIcon As Long    iIcon As Long    dwAttributes As Long    szDisplayName As String * MAX_PATH    szTypeName As String * 80End TypePublic Const SHGFI_ATTRIBUTES = &H800Public Const SFGAO_SHARE = &H20000Public Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" _    ( ByVal pszPath As String, ByVal dwFileAttributes As Long, _    psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long

Once you’ve called the function, check out the value of the dwAttributes field in the SHFILEINFO structure you passed in. If you AND that value with SFGAO_SHARE and obtain a nonzero value then the folder is shared.

Function IsFolderShared(ByVal folderName As String) As Boolean    Dim sfi As SHFILEINFO    SHGetFileInfo folderName, 0, sfi, Len(sfi), SHGFI_ATTRIBUTES    IsFolderShared = (sfi.dwAttributes And SFGAO_SHARE)End Function

This tip is taken from the book VisualC++ Windows Shell Programming by Dino Esposito.

See also  The Importance of Red Teaming in Modern Cyber Defense Strategies

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist