Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-08-27
5
Medium Priority
?
998 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
[X]
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
5 Comments
 
LVL 143

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:Robin
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:
Robin earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…
Suggested Courses

597 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