Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 994
  • Last Modified:

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:"

0
AllosIT
Asked:
AllosIT
  • 2
  • 2
1 Solution
 
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
 
Shift-3Commented:
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
 
AllosITAuthor Commented:
Thanks for all your help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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