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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 143

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

Robin 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

710 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