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
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]

     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

    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.
    LVL 1

    Author Comment

    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

    You can just simply assign it:


    LVL 1

    Author Closing Comment

    Thanks, robinu,
    That works a treat!
    Regards, Leigh

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    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…

    678 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

    Need Help in Real-Time?

    Connect with top rated Experts

    27 Experts available now in Live!

    Get 1:1 Help Now