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.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    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…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    913 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

    13 Experts available now in Live!

    Get 1:1 Help Now