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
================================

RE: drive mapping script - please tell me what I am missing by BaardSchyen

BaardSchyen
Fri Dec 15 16:48:01 CST 2006

Hi

It works for me, using WSHNetwork:

Option Explicit
Dim strDriveLetter, strRemotePath
Dim WSHNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive

strDriveLetter = "P:"
strRemotePath = "\\svrtest\my software" '(or "\\srvtest\mysoft~1")

Set objShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set CheckDrive = WSHNetwork.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
WSHNetwork.RemoveNetworkDrive strDriveLetter
WSHNetwork.MapNetworkDrive strDriveLetter, strRemotePath
objShell.PopUp "Drive " & strDriveLetter & " is already connected to " & _
strRemotePath
Else
WSHNetwork.MapNetworkDrive strDriveLetter, strRemotePath
objShell.PopUp "Drive " & strDriveLetter & " connected successfully."
End if

--
Regards,
Baard Schøyen


"WANNABE" wrote:

> 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
> ================================
>
>
>