Solved

Getting Shared Folders from a network Machine

Posted on 2002-06-17
4
186 Views
Last Modified: 2010-05-02
i want to get all shared folders from a network machine.

 for example,
 
 if i give : "\\admin4"
 The shared folders (subfolders of "\\admin4" ) in the   particulat machine ("\\admin4")
 should be listed :
   

  the Retrieving machine is not win2000/winnt server
  ( without using NETAPI32 )
 
help me urgently
0
Comment
Question by:sv_india_nan
4 Comments
 
LVL 5

Expert Comment

by:rpai
ID: 7089314
Please maintain your open questions:-
Questions Asked 2
Last 10 Grades Given  
Question Grading Record 0 Answers Graded / 0 Answers Received
0
 
LVL 1

Accepted Solution

by:
Form_Glow earned 45 total points
ID: 7108973
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright )1996-2002 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you can not publish
'               or reproduce this code on any web site,
'               on any online service, or distribute on
'               any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const ERROR_SUCCESS As Long = 0
Private Const MAX_PATH As Long = 260
Private Const CSIDL_NETWORK As Long = &H12
Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000

Private Type BROWSEINFO
   hOwner As Long
   pidlRoot As Long
   pszDisplayName As String
   lpszTitle As String
   ulFlags As Long
   lpfn As Long
   lParam As Long
   iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32" _
   Alias "SHGetPathFromIDListA" _
  (ByVal pidl As Long, _
   ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32" _
   Alias "SHBrowseForFolderA" _
  (lpBrowseInfo As BROWSEINFO) As Long

Private Declare Function SHGetSpecialFolderLocation Lib "shell32"_
  (ByVal hwndOwner As Long, _
   ByVal nFolder As Long, _
   pidl As Long) As Long
   
Private Declare Sub CoTaskMemFree Lib "ole32" _
   (ByVal pv As Long)  

   
Private Sub Command1_Click()
   
   Text1.Text = GetBrowseNetworkWorkstation()

End Sub


Private Sub Command2_Click()

   Text2.Text = GetBrowseNetworkShare()

End Sub

 
Private Function GetBrowseNetworkShare() As String

  'returns only a valid share on a
  'network server or workstation
   Dim BI As BROWSEINFO
   Dim pidl As Long
   Dim sPath As String
   Dim pos As Integer

  'obtain the pidl to the special folder 'network'
   If SHGetSpecialFolderLocation(Me.hWnd, _
                                 CSIDL_NETWORK, _
                                 pidl) = ERROR_SUCCESS Then
       
     'fill in the required members, limiting the
     'Browse to the network by specifying the
     'returned pidl as pidlRoot
      With BI
         .hOwner = Me.hWnd
         .pidlRoot = pidl
         .pszDisplayName = Space$(MAX_PATH)
         .lpszTitle = "Select a network computer or share."
         .ulFlags = BIF_RETURNONLYFSDIRS
      End With
         
     'show the browse dialog
      pidl = SHBrowseForFolder(BI)

      If pidl <> 0 Then
         
        'got a pidl .. but is it valid?
         sPath = Space$(MAX_PATH)

         If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
           'valid, so get the share path
            pos = InStr(sPath, Chr$(0))
            GetBrowseNetworkShare = Left$(sPath, pos - 1)
         End if  
         
         Call CoTaskMemFree(pidl)

      Else:
               
        'a server selected...follow same principle
        'as in GetBrowseNetworkWorkstation
         GetBrowseNetworkShare = "\\" & BI.pszDisplayName

      End If  'If pidl
   End If  'If SHGetSpecialFolderLocation

End Function


Private Function GetBrowseNetworkWorkstation() As String

  'returns only a valid network server or
  'workstation (does not display the shares)
   Dim BI As BROWSEINFO
   Dim pidl As Long
   Dim sPath As String
   Dim pos As Integer
   
  'obtain the pidl to the special folder 'network'
   If SHGetSpecialFolderLocation(Me.hWnd, _
                                 CSIDL_NETWORK, _
                                 pidl) = ERROR_SUCCESS Then
       
     'fill in the required members, limiting the
     'Browse to the network by specifying the
     'returned pidl as pidlRoot
      With BI
         .hOwner = Me.hWnd
         .pidlRoot = pidl
         .pszDisplayName = Space$(MAX_PATH)
         .lpszTitle = "Select a network computer."
         .ulFlags = BIF_BROWSEFORCOMPUTER
      End With
         
     'show the browse dialog. We don't need
     'a pidl, so it can be used in the If..then directly.        
      If SHBrowseForFolder(BI) <> 0 Then
               
         'a server was selected. Although a valid pidl
         'is returned, SHGetPathFromIDList only return
         'paths to valid file system objects, of which
         'a networked machine is not. However, the
         'BROWSEINFO displayname member does contain
         'the selected item, which we return
          GetBrowseNetworkWorkstation = "\\" & BI.pszDisplayName
           
      End If  'If SHBrowseForFolder
     
      Call CoTaskMemFree(pidl)
               
   End If  'If SHGetSpecialFolderLocation
   
End Function
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7911133
Hi sv_india_nan,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Form_Glow's comment(s) as an answer.

sv_india_nan, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7967796
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

21 Experts available now in Live!

Get 1:1 Help Now