Link to home
Start Free TrialLog in
Avatar of LeighWardle
LeighWardleFlag for Australia

asked on

VB6 code - using SHBrowseForFolder API Function - how to prevent access to network folders?

Hi Experts,

I am using VB^ code (see article here:  http://www.codeguru.com/vb/controls/vb_shell/article.php/c3051/ ) that uses the SHBrowseForFolder API Function.

How can I modify that code so that will either:

a. hide network folders?, OR
b. prevent access to network folders?

I already suspect a simple solution is to check for folders that start with "\\", but I am hoping for a more sophisicated solution.

Regards,
Leigh
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Hi,

 the following article shows which flag to set in the BROWSEINFO flags parameter to get which info displayed:
 http://msdn.microsoft.com/en-us/library/bb773205(VS.85).aspx

 which looks like you cannot hide the network folders directly.
 however, the hint in the last sentence is maybe what you need to apply in the callback functoin:
 
BIF_RETURNONLYFSDIRS
    0x0001. Only return file system directories. If the user selects folders that are not part of the file system, the OK button is grayed.
    Note  The OK button remains enabled for "\\server" items, as well as "\\server\share" and directory items. However, if the user selects a "\\server" item, passing the PIDL returned by SHBrowseForFolder to SHGetPathFromIDList fails.


note: I never did this in vb, so I don't know if it is possible with that API. I had implemented it once with the classical drivecombo + foldertreeview from vb...


You can solve your problem by setting the root folder.

You can use defined folders. See http://vbnet.mvps.org/index.html?code/browse/csidlversions.htm

Or set your own custom folder (e.g. C:\):

add declaration:
Private Declare Function SHSimpleIDListFromPath Lib "shell32" Alias "#162" (ByVal szPath As String) As Long

and in your example, change the BrowseForFolder function:

With tBrowseInfo
    .pIDLRoot = SHSimpleIDListFromPath(StrConv("C:\", vbUnicode))


And of course replacing the "C:\" with your custom directory.
Avatar of LeighWardle

ASKER

Hi Robinu,

I want to implement your proposed solution.

I can't figure out how to use CSIDL_DRIVES in this code:

With tBrowseInfo
    .pIDLRoot = SHSimpleIDListFromPath(StrConv("C:\", vbUnicode))

Regards,
Leigh
ASKER CERTIFIED SOLUTION
Avatar of Robin Uijt
Robin Uijt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, robinu,
That works a treat!
Regards, Leigh