On Error Resume Next
dim objNetwork, strDrive, objShell, objUNC
dim strRemotePath, strDriveLetter, strNewName
set wshNetwork = createObject("Wscript.Network")
strUsername = wshNetwork.UserName
call cleardrives() 'Delete all mapped drives...
call mapdrive("H:","\\SERVER\APPS","Applications")
call mapdrive("I:","\\SERVER02\NOTES","Field Notes")
call mapdrive("P:","\\SERVER03\Public","Public Share")
call mapdrive("Z:","\\SERVER03\" & strUsername & "$","Home Directory")
function cleardrives()
' This sections creates two objects:
' objShell and objNetwork and counts the drives
set objShell = createObject("WScript.Shell")
set objNetwork = createObject("WScript.Network")
set CheckDrive = objNetwork.EnumNetworkDrives()
' This section deletes all mapped network drives
on error resume next
for intDrive = 0 To CheckDrive.Count - 1 Step 2
if CheckDrive.Item(intDrive) <> strDriveLetter _
then objNetwork.RemoveNetworkDrive _
CheckDrive.Item(intDrive), bforce
next
end function
function mapdrive(strDriveLetter,strRemotePath,strNewName)
'Map the network drive
set objNetwork = createObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
'Rename the Mapped Drive
set objShell = createObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.name = strNewName
end function