# [SOLVED] vbs login script



## asmoa (May 20, 2009)

Hey, I don't have much experience with vbs so I'm looking for a bit of help!
This is the script that I'm currently running:

--------
ON ERROR RESUME NEXT
DIM objNetwork,colDrives,i
SET objNetwork = CREATEOBJECT("Wscript.Network")
SET colDrives = objNetwork.EnumNetworkDrives
FOR i = 0 to colDrives.Count-1 Step 2
' Force Removal of network drive and remove from user profile 
' objNetwork.RemoveNetworkDrive strName, [bForce], [bUpdateProfile]
objNetwork.RemoveNetworkDrive colDrives.Item(i),TRUE,TRUE
NEXT

Set objNetwork = CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive "G:" , "\\servername\sharename1"
objNetwork.MapNetworkDrive "S:" , "\\servername\sharename2"
objNetwork.MapNetworkDrive "T:" , "\\servername\sharename3"

---------

Currently this script removes all network drives, then maps g,s and t.I want to change this script so that it overrides existing drives with the same letter (g,s,t) but leaves all other drives that the client may have mapped themselves intact. (ex. usershare to a different server).

Any help would be greatly appreciated.

Thanks,

Chris


----------



## TheOutcaste (Mar 19, 2009)

*Re: vbs login script*

This should do it:

```
ON ERROR RESUME NEXT
DIM objNetwork
SET objNetwork = CREATEOBJECT("Wscript.Network")

' objNetwork.RemoveNetworkDrive strName, [bForce], [bUpdateProfile]
objNetwork.RemoveNetworkDrive "G:",TRUE,TRUE
objNetwork.RemoveNetworkDrive "S:",TRUE,TRUE
objNetwork.RemoveNetworkDrive "T:",TRUE,TRUE

objNetwork.MapNetworkDrive "G:" , "\\servername\sharename1"
objNetwork.MapNetworkDrive "S:" , "\\servername\sharename2"
objNetwork.MapNetworkDrive "T:" , "\\servername\sharename3"
```
HTH

Jerry


----------



## asmoa (May 20, 2009)

*Re: vbs login script*

Thanks for the reply Jerry.

This script seems like it would work, but if i have T mapped to t:\servername\d and run this script it wont remove the existing map and remap it to \\servername\sharename3

If no mapping initially existing for T, then it works great and maps t to \\servername\sharename3 like it should.

It doesn't seem to want to remove existing drive mappings.

Hope that makes sense.

Chris


----------



## asmoa (May 20, 2009)

*Re: vbs login script*

I ended up getting it to work by adding "wscript.sleep 300"

--------------------

ON ERROR RESUME NEXT
DIM objNetwork
SET objNetwork = CREATEOBJECT("Wscript.Network")

' objNetwork.RemoveNetworkDrive strName, [bForce], [bUpdateProfile]
objNetwork.RemoveNetworkDrive "G:",TRUE,TRUE
objNetwork.RemoveNetworkDrive "S:",TRUE,TRUE
objNetwork.RemoveNetworkDrive "T:",TRUE,TRUE

wscript.sleep 300

objNetwork.MapNetworkDrive "G:" , "\\servername\sharename1"
objNetwork.MapNetworkDrive "S:" , "\\servername\sharename2"
objNetwork.MapNetworkDrive "T:" , "\\servername\sharename3"

---------------------


----------



## TheOutcaste (Mar 19, 2009)

*Re: vbs login script*

Glad you figured it out. I tested by only removing one mapped drive so didn't run into the need for a delay to let the system catch up. I should have thought of that.

If your issue is resolved you can mark this thread *Solved* using the *Thread Tools* at the top of the thread on the right side.

Jerry


----------

