Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript to remove drives EXCEPT HOME (H:) DIR???

Status
Not open for further replies.

bran2235

IS-IT--Management
Feb 13, 2002
703
US
OK, before everyone tells me to look at the FAQs... I have! :)

I have ascript that deletes all mapped network drives, but I want to preserve their H: drive (user Home Dir).

Here's the basic remove all:

===============
On error resume next

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections

For i = 0 to colDrives.Count-1 Step 2
WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true
Next

For i = 0 to oPrinters.Count - 1 Step 2
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)

Next

==========================

How do I keep users' H: drive and remove all the others?


Thanks!!
Brandon
 
Something like:
Code:
For i = 0 to oDrives.Count-1 Step 2
If oDrives.Item(i) <> "H:" then WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true
Next
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
OK,
I tried this:
On error resume next

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections

For i = 0 to oDrives.Count-1 Step 2
If oDrives.Item(i) <> "H:" then WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true
Next


For i = 0 to oPrinters.Count - 1 Step 2
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)

Next
=========================

AND it still deletes everything.
I want to keep "H" and remove all others.

Thank yoU!!
 
What about this instead ?
Code:
For i = oDrives.Count-2 To 0 Step -2
  If oDrives.Item(i) <> "H:" Then
    WshNetwork.RemoveNetworkDrive oDrives.Item(i),True,True
  End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You Da Man, PHV!!
Worked great!!

Care to explain that to me??


THANK YOU!!
Brandon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top