remove network drives in a vb script

I have a VB script that connects my network drives without a problem. I added a section so i can remove certain drive letters and where they map to. I need to do this so i can remap the drives somewhere else the section i added to do the remove is below but it is not working.

Dim sUserID
Dim oGroup
Dim oNet
Dim colDrives
Dim sDomainName
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D


Set oNet = CreateObject("Wscript.Network")
sUserID = ""
On Error Resume Next
Do While sUserID = ""
  sUserID = oNet.UserName
Loop
On Error Goto 0
'wscript.echo sUserid

DriveMap()


Sub DriveMap()

'Remove mapped drives

On Error Resume Next
'oNet.RemoveNetworkDrive "E:"
'oNet.RemoveNetworkDrive "F:"
'oNet.RemoveNetworkDrive "G:"
'oNet.RemoveNetworkDrive "H:"
'oNet.RemoveNetworkDrive "I:"
'oNet.RemoveNetworkDrive "J:"
'oNet.RemoveNetworkDrive "K:"
'oNet.RemoveNetworkDrive "M:"
'oNet.RemoveNetworkDrive "N:"
'oNet.RemoveNetworkDrive "O:"
'oNet.RemoveNetworkDrive "P:"
'oNet.RemoveNetworkDrive "Q:"
'oNet.RemoveNetworkDrive "R:"
oNet.RemoveNetworkDrive "u:"

AllosITAsked:
Who is Participating?
 
Shift-3Connect With a Mentor Commented:
Try changing that line to
oNet.RemoveNetworkDrive "u:", True, True

This forces removal and also removes it from the user's profile.  See here for the full syntax:
http://msdn.microsoft.com/en-us/library/d16d7wbf(VS.85).aspx
0
 
Shift-3Commented:
Do you have an End Sub at the end of that?  What do get if you comment out the On Error Resume Next?

It might be simplest to use the script from this article to remove all network drives, and then map the ones you want.
http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey0915.mspx
0
 
AllosITAuthor Commented:
Yes i do have an End Sub. If I comment out the On Error Resume Next, I get the following VB script error:

Line: 39
Char: 1
Error: This network connection does not exist
Which is this line oNet.RemoveNetworkDrive "u:"
Here is a funny thing if i open the u drive before i run the script the it does not error and just disconnects the drive mapping but does not remove it.


0
 
AllosITAuthor Commented:
Thanks for all your help
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.

All Courses

From novice to tech pro — start learning today.