Suppose you have three mapped drives on your computer (drives X, Y, and Z). This is where the quirkiness of WSH’s mapped network drives collection manifests itself. First, though, let’s point out that the script starts off by creating an instance of the Wscript.Network object we then call the EnumNetworkDrives method to return a collection of all the mapped network drives on a computer. Yes, this is odd-looking code, but we’ll explain why it looks that way. ObjNetwork.RemoveNetworkDrive colDrives.Item(i) Set colDrives = objNetwork.EnumNetworkDrives Set objNetwork = CreateObject(“Wscript.Network”) So how do you remove all the mapped network drives on a computer? Here’s one way: On Error Resume Next That can be a bit inconvenient, to say the least (there’s no straightforward way to run a script that unmaps drives on a remote machine), but in this case it doesn’t matter that’s because logon scripts always run locally anyway. WSH does the job just fine, but with one caveat: WSH can map and unmap drives only on the local computer. Why? Well, one of the drawbacks to mapping and unmapping network drives is the fact that there are no WMI classes capable of performing these tasks that means we have to rely on Windows Script Host to remove mapped network drives. You know, we’re glad you specifically mentioned the term “logon script” in your question. Hey, Scripting Guy! How can I use a logon script to remove all mapped drives each time a user logs on?
0 Comments
Leave a Reply. |