enary
asked on
I have a problem with a script file not disconnecting and connecting drives
I have an issue with a script file not disconnecting and mapping a new drive. If I step throught the script it works everytime, but If I run it through without stops it will not work. Anyone have any ideas? Here is the example of the file.
Set objNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set objFSO = WScript.CreateObject("Scri pting.File SystemObje ct")
Set objShell = CreateObject("WScript.Shel l")
Set objNetwork = CreateObject("WScript.Netw ork")
Set CheckDrive = objNetwork.EnumNetworkDriv es()
Set MultiPrinter = CreateObject("WScript.Netw ork")
If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDr ive "I:", True, True
End If
objNetwork.MapNetworkDrive "I:", "\\wgh-maindc\install", false
Set objNetwork = WScript.CreateObject("WScr
Set objFSO = WScript.CreateObject("Scri
Set objShell = CreateObject("WScript.Shel
Set objNetwork = CreateObject("WScript.Netw
Set CheckDrive = objNetwork.EnumNetworkDriv
Set MultiPrinter = CreateObject("WScript.Netw
If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDr
End If
objNetwork.MapNetworkDrive
ASKER
same issue. If I step through it it works fine. If I take the breaks out it doesn't work. It is almost like it doesn't see any of the lines.
How are you running this anyways? VBS file, in a VB project, etc...
ASKER
I am running this as a VB script file for user logons. I am not gettting any error messages when I run this. I have never quite seen anything like this before. I am at a total loss. I removed the extra lines as suggested in the first response and tooks out the if statement, but it still won't work if I just run it. If I set the breaks and run it by stepping through those lines it disconects the old drives and maps the new drive. Take the breaks out and run it and it acts like it doesn't see those lines at all.
Option Explicit
'
Dim strDriveLetter1, strRemotePath1, strDriveLetter2, strRemotePath2, strPrint1, strPrint2, strPrint3, strOldPrint1, strOldPrint2, strOldPrint3
Dim strDriveLetter3, strRemotePath3, strDriveLetter4, strRemotePath4, strDriveLetter5, strRemotePath5
Dim strDriveLetter6, strRemotePath6
Dim objNetwork, objShell, objFSO
Dim CheckDrive, AlreadyConnected, intCounter
Dim MultiPrinter, UNCpath1, UNCpath2, UNCpath3
'On Error Resume Next
Set objNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set objFSO = WScript.CreateObject("Scri pting.File SystemObje ct")
Set objShell = CreateObject("WScript.Shel l")
Set objNetwork = CreateObject("WScript.Netw ork")
Set CheckDrive = objNetwork.EnumNetworkDriv es()
Set MultiPrinter = CreateObject("WScript.Netw ork")
'If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDr ive "I:", True, True
'End If
objNetwork.MapNetworkDrive "I:", "\\wgh-maindc\install", false
If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDr ive "I:", False, True
End If
objNetwork.MapNetworkDrive "I:", "\\wgh-maindc\install", false
Option Explicit
'
Dim strDriveLetter1, strRemotePath1, strDriveLetter2, strRemotePath2, strPrint1, strPrint2, strPrint3, strOldPrint1, strOldPrint2, strOldPrint3
Dim strDriveLetter3, strRemotePath3, strDriveLetter4, strRemotePath4, strDriveLetter5, strRemotePath5
Dim strDriveLetter6, strRemotePath6
Dim objNetwork, objShell, objFSO
Dim CheckDrive, AlreadyConnected, intCounter
Dim MultiPrinter, UNCpath1, UNCpath2, UNCpath3
'On Error Resume Next
Set objNetwork = WScript.CreateObject("WScr
Set objFSO = WScript.CreateObject("Scri
Set objShell = CreateObject("WScript.Shel
Set objNetwork = CreateObject("WScript.Netw
Set CheckDrive = objNetwork.EnumNetworkDriv
Set MultiPrinter = CreateObject("WScript.Netw
'If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDr
'End If
objNetwork.MapNetworkDrive
If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDr
End If
objNetwork.MapNetworkDrive
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Finally, it works.
You can give this a shot. Basically I just got rid of the excess object declares, added error handling and removed checking for drive existence via FileSystemObject, so that you're only using a single object that you can blame if there is a failure.
On Error Resume Next
Set objNetwork = WScript.CreateObject("WScr
objNetwork.RemoveNetworkDr
objNetwork.MapNetworkDrive