Solved

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

Posted on 2008-08-27
5
875 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
Comment
Question by:LeighWardle
  • 2
  • 2
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22322690
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
ID: 22322917
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
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))

Regards,
Leigh
0
 
LVL 16

Accepted Solution

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

.pIDLRoot=CSIDL_DRIVES

0
 
LVL 1

Author Closing Comment

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

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