Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Aug 7, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.

    hIcon As Long
    iIcon As Long
    dwAttributes As Long
    szDisplayName As String * MAX_PATH
    szTypeName As String * 80
End Type

Public Const SHGFI_ATTRIBUTES = &H800
Public Const SFGAO_SHARE = &H20000

Public 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 Visual C++ Windows Shell Programming by Dino Esposito.
Dino Esposito
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date