Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disconnect drives based on the server they are mapped to

Status
Not open for further replies.

nerram

Programmer
Apr 23, 2003
56
0
0
IE
Hi,
I was wondering is there anyway to delete all drives mapped to a server. e.g see below
drive server
f:\ \\server1\share1
g:\ \\server1\share2
h:\ \\server2\share1
j:\ \\server2\share2
k:\ \\server1\share3

In this scenario I would like to delete f,g and k but leave h and j connected. The drives can be enumerated to any letter so I only want the drive to be disconnected based on what it is connected to. Any ideas?
 
Set Wn = WScript.CreateObject ("WScript.Network")

'disconnect drive
Wn.RemoveNetworkDrive "f:"

Might work
 
Not quite what I am looking for. I need the connection to be shut down based on the server it is connected to.
 
Take a look at the WshNetwork.EnumNetworkDrives collection.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Problem Solved Here is what I done:
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set clDrives = WshNetwork.EnumNetworkDrives
strServer = WScript.Arguments(0)

For i = 0 to clDrives.Count -1 step 2
If UCase(strServer) = UCase(Left (clDrives.Item(i+1), Len(strServer))) Then
WshNetwork.RemoveNetworkDrive clDrives.Item(i), TRUE
End If
Next

The argument here being for example \\server1\
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top