DeleteNetworkDrives()

code

' -------------------------------------------
' DeleteNetworkDrives()
' Deletes network devices given as argument,
' if they exist.
' -------------------------------------------
Sub DeleteNetworkDrives(objWshNet, arrDriveList)
Dim colExistingDrives, i, strDrive

' List existing network drives
Set colExistingDrives = objWshNet.EnumNetworkDrives

WScript.StdOut.Write "Deletes devices: "
' For each network drive... see if it's in the list of drives that should be unmapped
For i = 0 To colExistingDrives.Count-2 Step 2
'WScript.StdOut.Write colExistingDrives.Item(i) & ", " 'DBG
For Each strDrive In arrDriveList
If strDrive = colExistingDrives.Item(i) Then
WScript.StdOut.Write colExistingDrives.Item(i) & " " 'DBG
objWshNet.RemoveNetworkDrive strDrive, True, True 'It is! Unmap it!
End If
Next
Next
WScript.StdOut.WriteLine " ...done!"
End Sub

example

Set objWshNet = WScript.CreateObject("WScript.Network")

DeleteNetworkDrives objWshNet, Array("I:", "J:", "P:", "T:", "M:")

description

Removes the specified mapped network drives (forcefully).
Requires:  A WScript.Network object and an array consisting of the device names that should be unmapped
Returns:  Nothing