Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I have a problem with a script file not disconnecting and connecting drives

Posted on 2011-09-06
6
Medium Priority
?
238 Views
Last Modified: 2012-05-12
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("WScript.Network")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
Set MultiPrinter = CreateObject("WScript.Network")

If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDrive "I:", True, True
End If
objNetwork.MapNetworkDrive "I:", "\\wgh-maindc\install", false
0
Comment
Question by:enary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:MaximumIQ
ID: 36491392
I'm not sure if you're getting an error or not when running the script. Honestly though, I don't see any problems with your method but i'm guessing the issue might be FileSystemObject not detecting the drive, therefore not disconnecting it and in turn the MapNetworkDrive is not doing anything.

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("WScript.Network")

objNetwork.RemoveNetworkDrive "I:", True, True
objNetwork.MapNetworkDrive "I:", "\\wgh-maindc\install", false
0
 

Author Comment

by:enary
ID: 36491628
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.
0
 
LVL 4

Expert Comment

by:MaximumIQ
ID: 36492062
How are you running this anyways? VBS file, in a VB project, etc...
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:enary
ID: 36492116
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("WScript.Network")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
Set MultiPrinter = CreateObject("WScript.Network")

'If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDrive "I:", True, True
'End If
objNetwork.MapNetworkDrive "I:", "\\wgh-maindc\install", false

If objFSO.DriveExists("I:") Then
objNetwork.RemoveNetworkDrive "I:", False, True
End If
objNetwork.MapNetworkDrive "I:", "\\wgh-maindc\install", false
0
 
LVL 4

Accepted Solution

by:
MaximumIQ earned 2000 total points
ID: 36492326
Ok so I tested this my self and I found that when the script pointing to \\Server2\Folder2 runs, while there is an I: Drive already mapped to \\Server1\Folder1 , it appears by looking at my computer that nothing changed, however the path did change, it just doesn't update in the windows GUI. So when I opened "Folder1 (\\Server1) (I:)" it actually opened "\\Server2\Folder2"

I'm not sure if this is the same thing that's happening on your end or not, but if it is, you can take care of it by adding a 5 second or so pause after unmapping the old drive and mapping the new one.

So something like this

 
Option Explicit
On Error Resume Next

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

Set objNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
Set MultiPrinter = CreateObject("WScript.Network")

If objFSO.DriveExists("I:") Then
	objNetwork.RemoveNetworkDrive "I:", True, True
End If

wscript.sleep 5

objNetwork.MapNetworkDrive "I:", "\\wgh-maindc\install", false

Open in new window

0
 

Author Closing Comment

by:enary
ID: 37285220
Finally, it works.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I wanted to share this with fellow Experts, who might not know. How often have you wanted to learn something, only to be set back by either restrictions imposed on "trial" or "evaluation" software?  How often have you had to rebuild a home networ…
Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question