Option Explicit
Dim objNet, objDrive, i, objShell
' enumerate the mapped drives
Set objNet = CreateObject("WScript.Network")
Set objDrive = objNet.EnumNetworkDrives
Set objShell = CreateObject("WScript.Shell")
If objDrive.Count <> 0 Then
' List all network drives
For i = 0 To (objDrive.Count -1) Step 2
WScript.Echo "UNC Path " & objDrive.Item(i) & " is mapped to " & objDrive.Item(i +1)
IF Instr(objDrive.Item(i+1), "172.108.162.47") > 0 Then
WScript.Echo "Match found, disconnecting from " & objDrive.Item(i+1)
If objDrive.Item(i) <> "" Then
objNet.RemoveNetworkDrive objDrive.Item(i), True
Else
objShell.Run "net use " & objDrive.Item(i+1) & " /del /y"
End If
End If
Next
End If
Wscript.Quit
|