?
Solved

disconnecting a mapped drive and mapping a new drive to the same drive letter

Posted on 2006-05-11
12
Medium Priority
?
351 Views
Last Modified: 2010-04-13
I am running a master.vbs script that executes two other scripts, disconnecto.vbs and mapo.vbs

disconnecto.vbs disconnects the current o: mapping and mapo.vbs is supposed to map a new drive using the same drive letter...but it does not work. The drive gets disconnected by the first script, but is not REMOVED so that the 2nd script can create the new mapping with the same letter. Here's my scripts:

disconnecto.vbs:

 'Initialization Section

Option Explicit

on Error Resume Next

Dim objWshNet

'Instantiate the objWshNetwork object
Set objWshNet = Wscript.CreateObject("WScript.Network")

'Main Processing Section

'Call procedure that deletes network drive connections, passing it the
'drive letter to be removed
MapNetworkDrive "o:"

WScript.Quit() 'Terminate script execution

'Procedure Section

'This subroutine disconnects the specified network drive connection

Sub MapNetworkDrive(DriveLetter)

  'Use the objWshNetwork object's RemoteNetworkDrive() method to disconnect
  'the specified network drive
  objWshNet.RemoveNetworkDrive DriveLetter, True

End Sub

_________________________

mapo.vbs:

'Initialization section

Option Explicit

On Error Resume Next

Dim objWshNet

'Instantiate the objWshnetwork object
Set objWshNet = WScript.CreateObject("WScript.Network")

'Main Processing Section

'Call the procedure that maps drive connections passing it an available
'drive letter and the UNC pathname of the drive
MapNetworkDrive "o:", "\\sql2\apps$"

WScript.Quit() 'Terminate script execution

'Procedure Section

'This subroutine creates network drive mappings
Sub MapNetworkDrive(DriveLetter, NetworkPath)

'use the objWshNetwork object's MapNetworkDrive() method to map to drive
objWshNet.MapNetworkDrive DriveLetter, NetworkPath

End Sub



How can i accomplish this?

Thanks
0
Comment
Question by:scott2000666
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 48

Expert Comment

by:Jay_Jay70
ID: 16663608
Hi scott2000666,

try adding this to your second scirpt which maps the drive again - itsmore a vbs line so you can incorp how you wish

If Exist x:\ Net use x: /delete
0
 

Author Comment

by:scott2000666
ID: 16663650
where, in the script, should it go exactly?
0
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 16663704
Jay Jay - this is a vbs logon script - that command is a batch command.
0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 

Author Comment

by:scott2000666
ID: 16663725
honestly, it doesn't matter to me if I use a batch script or a vbs script to accomplish this. whatever works...thus far, I can't seem to get it to work either way...
0
 

Author Comment

by:scott2000666
ID: 16663736
ok...I got it to work like this:

net use o: /delete /y
net use o: "\\sql2\apps$" /y

0
 
LVL 48

Expert Comment

by:Jay_Jay70
ID: 16663739
ah my apologies, my scripting abilites are only just in the learning stage so forgive my stupidness....
0
 

Author Comment

by:scott2000666
ID: 16663740
I WOULD like to know how to add something to the vbs script, though, to make that work...so if someone can answer this, i will award them the points.
0
 
LVL 6

Expert Comment

by:itdrms
ID: 16675537
FYI -- I've had problems using the /delete in scripting if the drive does not exist -- it will error out the script, so test with o: disconnected.
If you're happy with the DOS commands -- can you just use the DOS commands in your vbs script?

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Run "cmd /c net use o: /delete /y"
set WSHShell = Nothing
0
 
LVL 4

Expert Comment

by:zivko
ID: 16713551
Have a look in the event viewer, what error is reported by WSH?
You may found what causes this problem, as your script is working well, it must be linked to something else.
Does the share name contain a space? It this case, it my be required to add quotes in your script (for example: MapNetworkDrive "O:", """" & "\\SERVER\SHARE NAME" & """" ?

Just to test, comment out "On Error Resume Next" to see the error message appearing on screen, what is it?
0
 
LVL 4

Accepted Solution

by:
zivko earned 500 total points
ID: 16713612
The only way I've found to reproduce the problem is as follow:

When the Drive Map is permanent (saved in user's profile), your script doesn't work.
You need to specify the parameter to remove the map fron it, adding one more "True" parameter:

Your function:
----------------
Sub MapNetworkDrive(DriveLetter)
  objWshNet.RemoveNetworkDrive DriveLetter, True
End Sub

Modified to specifiy (set) the "bUpdateProfile" parameter:
-----------------------------------------------------------------
Sub MapNetworkDrive(DriveLetter)
  objWshNet.RemoveNetworkDrive DriveLetter, True, True
End Sub
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 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