Line wraps may make this hard to read, I hope someone can help me, please..
With the drive letter mapped, this seems to go right past the REMOVE line,
but still displays the message that the new drive was mapped. If I remove
the MAP line, it will remove the drive and display the message, the next run
maps the drive. Then I remap the drive to something else and start testing
all over again, but it seems that the 2 lines <<Just found a fix, will post
at the end... >>> Can someone explain this???? PLEASE
Option Explicit
Dim strDriveLetter, strRemotePath
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
strDriveLetter = "P:"
strRemotePath = "\\svrtest\my software"
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter Then AlreadyConnected =True
Next
If AlreadyConnected = True then
objNetwork.RemoveNetworkDrive strDriveLetter
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
objShell.PopUp "Drive " & strDriveLetter & " is now connected to " &
strRemotePath
Else
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
objShell.PopUp "Drive " & strDriveLetter & " connected successfully."
End if
WScript.Quit
SWAPPED these 2 lines
objNetwork.RemoveNetworkDrive strDriveLetter
objShell.PopUp "Drive " & strDriveLetter & " is now connected to " &
strRemotePath
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
================================