Results 1 to 5 of 5

Thread: List shared Folders on network

  1. #1

    Thread Starter
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    List shared Folders on network

    How do you list all shared folders on a particular network pc.

    Thanks

    Rob
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  2. #2

    Thread Starter
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    Re: List shared Folders on network

    After quite an extensive search no one seems to know how to do it.

    The only way I can think of is to use perl script to list all of the folders - then use vb to parse the output. I used this perl script:
    Code:
    use strict;
    
    my $res;
    
    $res = `net view`;
    
    my @computers;
    
    @computers = split(/\\/, $res);
    
    foreach (@computers)
    {
    	$_ =~ /([^ ]*) /;
    	my $pc = $1;
    
    	$res = `net view \\\\$pc`;
    	print $res;
    
    }
    Anyone got a better way?
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: List shared Folders on network

    If I understand you correctly you want to list shared folders simular to how they are listed in the Network Neighborhood, is that correct?

    To do so you would use WNetOpenEnum to start the enumeration of network resources and then keep calling WNetEnumResources until it returns ERROR_NO_MORE_ITEMS. I could write a demo for you if you can't figure it out from this information but I don't have time at the moment so that have to wait a few hours.

  4. #4

    Thread Starter
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    Re: List shared Folders on network

    VB Code:
    1. Private Const RESOURCE_CONNECTED As Long = &H1&
    2. Private Const RESOURCE_GLOBALNET As Long = &H2&
    3. Private Const RESOURCE_REMEMBERED As Long = &H3&
    4. Private Const RESOURCEDISPLAYTYPE_DIRECTORY& = &H9
    5. Private Const RESOURCEDISPLAYTYPE_DOMAIN& = &H1
    6. Private Const RESOURCEDISPLAYTYPE_FILE& = &H4
    7. Private Const RESOURCEDISPLAYTYPE_GENERIC& = &H0
    8. Private Const RESOURCEDISPLAYTYPE_GROUP& = &H5
    9. Private Const RESOURCEDISPLAYTYPE_NETWORK& = &H6
    10. Private Const RESOURCEDISPLAYTYPE_ROOT& = &H7
    11. Private Const RESOURCEDISPLAYTYPE_SERVER& = &H2
    12. Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3
    13. Private Const RESOURCEDISPLAYTYPE_SHAREADMIN& = &H8
    14. Private Const RESOURCETYPE_ANY As Long = &H0&
    15. Private Const RESOURCETYPE_DISK As Long = &H1&
    16. Private Const RESOURCETYPE_PRINT As Long = &H2&
    17. Private Const RESOURCETYPE_UNKNOWN As Long = &HFFFF&
    18. Private Const RESOURCEUSAGE_ALL As Long = &H0&
    19. Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1&
    20. Private Const RESOURCEUSAGE_CONTAINER As Long = &H2&
    21. Private Const RESOURCEUSAGE_RESERVED As Long = &H80000000
    22. Private Const ERROR_NO_MORE_ITEMS = 259&
    23. Private Const NO_ERROR = 0
    24. Private Const ERROR_MORE_DATA = 234                        'L // dderror
    25. Private Const RESOURCE_ENUM_ALL As Long = &HFFFF
    26. Private Type NETRESOURCE
    27.     dwScope As Long
    28.     dwType As Long
    29.     dwDisplayType As Long
    30.     dwUsage As Long
    31.     pLocalName As Long
    32.     pRemoteName As Long
    33.     pComment As Long
    34.     pProvider As Long
    35. End Type
    36. Private Type NETRESOURCE_REAL
    37.     dwScope As Long
    38.     dwType As Long
    39.     dwDisplayType As Long
    40.     dwUsage As Long
    41.     sLocalName As String
    42.     sRemoteName As String
    43.     sComment As String
    44.     sProvider As String
    45. End Type
    46. Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
    47. Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) As Long
    48. Private Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, lpBuffer As NETRESOURCE, lpBufferSize As Long) As Long
    49. Private Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long
    50. Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (lpTo As Any, lpFrom As Any, ByVal lLen As Long)
    51. Private Declare Sub CopyMemByPtr Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpTo As Long, ByVal lpFrom As Long, ByVal lLen As Long)
    52. Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Any) As Long
    53. Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
    54.  
    55. Private Function ListAllSharedFolders() As Collection
    56.     Const MAX_RESOURCES = 256
    57.     Const NOT_A_CONTAINER = -1
    58.     Dim bFirstTime As Boolean
    59.     Dim lReturn As Long
    60.     Dim hEnum As Long
    61.     Dim lCount As Long
    62.     Dim lMin As Long
    63.     Dim lLength As Long
    64.     Dim l As Long
    65.     Dim lBufferSize As Long
    66.     Dim lLastIndex As Long
    67.     Dim uNetApi(0 To MAX_RESOURCES) As NETRESOURCE
    68.     Dim uNet() As NETRESOURCE_REAL
    69.     Dim col As Collection
    70.    
    71.     Set col = New Collection
    72.     bFirstTime = True
    73.     Do
    74.         If bFirstTime Then
    75.             lReturn = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, ByVal 0&, hEnum)
    76.             bFirstTime = False
    77.         Else
    78.             If uNet(lLastIndex).dwUsage And RESOURCEUSAGE_CONTAINER Then
    79.                 lReturn = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, uNet(lLastIndex), hEnum)
    80.             Else
    81.                 lReturn = NOT_A_CONTAINER
    82.                 hEnum = 0
    83.             End If
    84.             lLastIndex = lLastIndex + 1
    85.         End If
    86.         If lReturn = NO_ERROR Then
    87.             lCount = RESOURCE_ENUM_ALL
    88.             Do
    89.                 lBufferSize = UBound(uNetApi) * Len(uNetApi(0)) / 2
    90.                 lReturn = WNetEnumResource(hEnum, lCount, uNetApi(0), lBufferSize)
    91.                 If lCount > 0 Then
    92.                     ReDim Preserve uNet(0 To lMin + lCount - 1) As NETRESOURCE_REAL
    93.                     For l = 0 To lCount - 1
    94.                         uNet(lMin + l).dwScope = uNetApi(l).dwScope
    95.                         uNet(lMin + l).dwType = uNetApi(l).dwType
    96.                         uNet(lMin + l).dwDisplayType = uNetApi(l).dwDisplayType
    97.                         uNet(lMin + l).dwUsage = uNetApi(l).dwUsage
    98.                         If uNetApi(l).pLocalName Then
    99.                             lLength = lstrlen(uNetApi(l).pLocalName)
    100.                             uNet(lMin + l).sLocalName = Space$(lLength)
    101.                             CopyMem ByVal uNet(lMin + l).sLocalName, ByVal uNetApi(l).pLocalName, lLength
    102.                         End If
    103.                         If uNetApi(l).pRemoteName Then
    104.                             lLength = lstrlen(uNetApi(l).pRemoteName)
    105.                             uNet(lMin + l).sRemoteName = Space$(lLength)
    106.                             CopyMem ByVal uNet(lMin + l).sRemoteName, ByVal uNetApi(l).pRemoteName, lLength
    107.                         End If
    108.                         If uNetApi(l).pComment Then
    109.                             lLength = lstrlen(uNetApi(l).pComment)
    110.                             uNet(lMin + l).sComment = Space$(lLength)
    111.                             CopyMem ByVal uNet(lMin + l).sComment, ByVal uNetApi(l).pComment, lLength
    112.                         End If
    113.                         If uNetApi(l).pProvider Then
    114.                             lLength = lstrlen(uNetApi(l).pProvider)
    115.                             uNet(lMin + l).sProvider = Space$(lLength)
    116.                             CopyMem ByVal uNet(lMin + l).sProvider, ByVal uNetApi(l).pProvider, lLength
    117.                         End If
    118.                        
    119.                        
    120.                         If uNet(lMin + l).dwDisplayType = RESOURCEDISPLAYTYPE_SHARE Then
    121.                             'List1.AddItem uNet(lMin + l).sRemoteName
    122.                             col.Add uNet(lMin + l).sRemoteName
    123.                         End If
    124.                     Next l
    125.                 End If
    126.                 lMin = lMin + lCount
    127.             Loop While lReturn <> ERROR_NO_MORE_ITEMS 'ERROR_MORE_DATA
    128.         End If
    129.         If hEnum Then
    130.             l = WNetCloseEnum(hEnum)
    131.         End If
    132.     Loop While lLastIndex < lMin
    133.  
    134.     Set ListAllSharedFolders = col
    135. End Function

    Rob
    Last edited by THEROB; Jul 7th, 2005 at 04:10 AM.
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  5. #5
    Lively Member
    Join Date
    Oct 2009
    Location
    Gran Canaria, Spain.
    Posts
    101

    Re: List shared Folders on network

    Just found this........... thanks
    Last edited by BriansBrain; Mar 11th, 2018 at 10:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width