Wscript fails to map drives
Posted on 2009-05-05
So I'm mapping replicated servers per each location (via IP address) with a VBS Wscript. The problem I am experiencing is failure for some computers to map the drives that are specified in the script. Each of the computers failing to map have dual nic's. (Dual Ethernet or Ethernet and WLAN)
It appears that the NIC's that are disconnected are somehow taking priority over the connected NIC. Wireless nics appear to always be the NIC that take priority or that are checked against the script even when disconnected. Can anyone tell me how to fix this? Is there something I need to modify or add to my script to check all or active connections? Maybe something in the registry needs to be modified?
Here is my VBS Wscript.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = "."
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")
For Each objAdapter in colAdapters
For Each strAddress in objAdapter.IPAddress
arrOctets = Split(strAddress, ".")
If arrOctets(0) <> "" Then
strSubnet = arrOctets(0) & "." & arrOctets(1) & "." & arrOctets(2)
x = 1
If x = 1 Then
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DeviceID = 'W:'")
If colItems.Count = 0 Then
Select Case strSubnet
objNetwork.MapNetworkDrive "W:", "\\fry\WAFS"
objNetwork.MapNetworkDrive "W:", "\\TinnyTim\WAFS"
objNetwork.MapNetworkDrive "W:", "\\Destructor\WAFS"
objNetwork.MapNetworkDrive "W:", "\\Boxy\WAFS"