• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

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

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
scott2000666
Asked:
scott2000666
  • 4
  • 2
  • 2
  • +2
1 Solution
 
Jay_Jay70Commented:
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
 
scott2000666Author Commented:
where, in the script, should it go exactly?
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Jay Jay - this is a vbs logon script - that command is a batch command.
0
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.

 
scott2000666Author Commented:
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
 
scott2000666Author Commented:
ok...I got it to work like this:

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

0
 
Jay_Jay70Commented:
ah my apologies, my scripting abilites are only just in the learning stage so forgive my stupidness....
0
 
scott2000666Author Commented:
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
 
itdrmsCommented:
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
 
zivkoCommented:
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
 
zivkoCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now