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

Posted on 2008-08-27
Last Modified: 2012-06-21
Hi Experts,

I am using VB^ code (see article here: ) 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.

Question by:LeighWardle
  • 2
  • 2
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22322690

 the following article shows which flag to set in the BROWSEINFO flags parameter to get which info displayed:

 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:
    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...

LVL 16

Expert Comment

ID: 22322917
You can solve your problem by setting the root folder.

You can use defined folders. See

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.

Author Comment

ID: 22324094
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))

LVL 16

Accepted Solution

robinu earned 500 total points
ID: 22324124
You can just simply assign it:



Author Closing Comment

ID: 31490603
Thanks, robinu,
That works a treat!
Regards, Leigh

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA to copy paste columns form one file to other 20 88
Adding to a VBA? 6 70
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 47
VBA Shell can't Find Word document 11 94
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question