Dim fserv As Object
Dim share As Object
Dim shareNew As Object
Dim ShareRoot As String
Function 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 If
AbortFunction:
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 Function
Private 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 share
End 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