感谢您使用微软产品。您可以通过ADSI方式的IADsFileShare对象得到目录的共享信息包括共享名,再用函数Dir获得递归获得目录下的所有文件。 如下例:Dim fserv As Object
Dim share As Object
Dim shareNew As Object
Dim ShareRoot As StringFunction FindDirs(path As String)      Dim DirName As String    ' SubDirectory Name.
      Dim dirNames() As String ' Buffer for directory name entries.
      
      Dim nDir As Integer      ' Number of directories in this path.
      Dim i As Integer         ' For-loop counter.      On Error GoTo sysFileERR
      If Right(path, 1) <> "\" Then path = path & "\"
      ' Search for subdirectories.
      nDir = 0
      ReDim dirNames(nDir)
      DirName = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly _
Or vbSystem)  ' Even if hidden, and so on.
      Do While Len(DirName) > 0
         ' Ignore the current and encompassing directories.
         If (DirName <> ".") And (DirName <> "..") Then
            ' Check for directory with bitwise comparison.
            If GetAttr(path & DirName) And vbDirectory Then
               dirNames(nDir) = DirName
               nDir = nDir + 1
               ReDim Preserve dirNames(nDir)
              ' List1.AddItem path & DirName ' Uncomment to list
            End If                           ' directories.
sysFileERRCont:
         End If
         List1.AddItem path & DirName
         DirName = Dir()  ' Get next subdirectory.
      Loop      ' If there are sub-directories..
      If nDir > 0 Then
         ' Recursively walk into them
         For i = 0 To nDir - 1
           FindDirs = FindDirs + FindDirs(path & dirNames(i) & "\")
         Next i
      End IfAbortFunction:
      Exit Function
sysFileERR:
      If Right(DirName, 4) = ".sys" Then
        Resume sysFileERRCont ' Known issue with pagefile.sys
      Else
        MsgBox "Error: " & Err.Number & " - " & Err.Description, , _
         "Unexpected Error"
        Resume AbortFunction
      End If
End FunctionPrivate Sub Command1_Click()     ShareRoot = "WinNT://"      Set fserv = GetObject("WinNT://COMPUTERNAME/LanmanServer")
      
      Debug.Print "**************************"      For Each share In fserv
           Debug.Print share.Name
           Debug.Print share.Path
           Debug.Print share.Class
           Debug.Print share.HostComputer
    FindStr = "\" + "\" + ComputerNameStr + "\" + share.Name
           Debug.Print FindStr
           FileSize = FindDirs(FindStr)
      Next shareEnd Sub请参考下面的例子:
Q234234 How to Manage File Shares Using ADSI
http://support.microsoft.com/support/kb/articles/q234/2/34.asp
Q169398 HOWTO: Manipulate File Shares with ADSI (VB Sample)
http://support.microsoft.com/support/kb/articles/q169/3/98.asp
HOWTO: Search Directories to Find or List Files (Q185476)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q185476-  微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。

解决方案 »

  1.   

    我还有办法。微软全球技术中心 VB技术支持 的那篇文章回复的很不错。
    我这里有个 DLL 可以解决这些问题,你只需要通过一个方法调用就可以
    获取共享文件夹信息。该 DLL 还包括其他方法,如:取用户名|机器名|域
    名方法,取指定机器的共享文件夹|可用服务方法,启动停止某一服务方法
    等等。有兴趣可以联系我:[email protected]