VBA 搜索共享资源

来源:互联网 发布:剑三成男天策捏脸数据 编辑:程序博客网 时间:2024/06/06 02:58

'添加引用 Windows Script Host Object Model

Sub SearchShared()

   Dim a As WshNetwork
   Dim oPrinter As WshCollection
   Set a = New WshNetwork
   Set oPrinter = a.EnumPrinterConnections
   Debug.Print "Network printer mappings:"
   For i = 0 To oPrinter.Count - 1 Step 2
       Debug.Print "Port" & oPrinter.Item(i) & oPrinter.Item(i + 1)
   Next
 
   Dim colDrives As WshCollection
   Set colDrives = a.EnumNetworkDrives
   If colDrives.Count = 0 Then
      MsgBox "no drive"
   Else
   MsgBox colDrives.Count
      strmsg = "当前网络驱动器连接:" & crlf
   
      For i = 0 To colDrives.Count - 1 Step 1
   
         Debug.Print colDrives(i)
      Next
  
   End If
   
End Sub

原创粉丝点击