Solved

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

Posted on 2008-08-27
819 Views
Last Modified: 2012-06-21
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
0
Question by:LeighWardle
    5 Comments
     
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    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...


    0
     
    LVL 16

    Expert Comment

    by:robinu
    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.
    0
     
    LVL 1

    Author Comment

    by:LeighWardle
    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
    0
     
    LVL 16

    Accepted Solution

    by:
    You can just simply assign it:

    .pIDLRoot=CSIDL_DRIVES

    0
     
    LVL 1

    Author Closing Comment

    by:LeighWardle
    Thanks, robinu,
    That works a treat!
    Regards, Leigh
    0

    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