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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If network drive exists

Status
Not open for further replies.

Steel811

Programmer
Jan 2, 2008
26
0
0
US
Hello,

I would like to do a simple task that entails checking to see if a specific drive mapping exists, remove that mapping, and then re-map those letters to a new path. Does anyone know how this can be done in VBscript? It is probably better explained in this pseudo code...

If Network drive (z: and y:) exists then
removenetworkdrive "z:"
removenetworkdrive "y:"
mapnetworkdrive "z:" "\\UNC\Path"
mapnetworkdrive "y:" "\\UNC\Path2"
else
mapnetworkdrive "z:" "\\UNC\Path"
mapnetworkdrive "y:" "\\UNC\Path2"
end if

Thanks,
sheel
 
Well, the FileSystemObject has a .DriveExists() method that would tell you if the mapping is there or not. The WshNetwork object has a .MapNetworkDrive() method that will do the mapping.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I wouldnt bother checking to see if they are mapped already, doesnt really matter if they are or not. Just disconnect the drives if they exist, if they dont exist the script will just move on.

Disconnect the drives:
WshNetwork.RemoveNetworkDrive "Y:","True","True"
WshNetwork.RemoveNetworkDrive "Z:","True","True"

Map the new drive:
WSHNetwork.MapNetworkDrive "Y:", "\\Computer or server\share","True"
WSHNetwork.MapNetworkDrive "Z:", "\\Computer or server\share","True"

See markdmac's FAQ for more detail:



RoadKi11

"This apparent fear reaction is typical, rather than try to solve technical problems technically, policy solutions are often chosen." - Fred Cohen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top