I know very little about netsh.exe. Try this script instead:
[01] '-------------------------
[02] 'Disable disconnected NICs
[03] 'Prerequisite: devcon.exe
[04] '19.8.2009 FNL
[05] '-------------------------
[06] sDevcon = "d:\Tools\devcon.exe"
[07] iEthernet = 0: iWireless = 9
[08] Set oWshShell = CreateObject("WScript.Shell")
[09]
[10] '-------------------------
[11] 'Get a list of all devices
[12] '-------------------------
[13] WScript.Echo "Compiling the device list"
[14] Set oExec = oWshShell.Exec(sDevcon & " HWIDs *")
[15] WScript.Sleep 5000
[16] sResult = ""
[17] While Not oExec.StdOut.AtEndOfStream
[18] sResult = sResult & oExec.StdOut.ReadLine & "|"
[19] Wend
[20] aDeviceInfo = Split(sResult, "|")
[21]
[22] '---------------------------------
[23] 'Check which adapters are disabled
[24] '---------------------------------
[25] Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
[26] Set colItems = oWMIService.ExecQuery(_
[27] "SELECT * FROM Win32_NetworkAdapter", , 48)
[28] For Each oItem In colItems
[29] If (oItem.AdapterTypeId = iEthernet _
[30] Or oItem.AdapterTypeId = iWireless) _
[31] And oItem.NetConnectionStatus = 7 _
[32] Then DisableAdapter(oItem.Name)
[33] Next
[34]
[35] '-----------------------------
[36] 'Disable disconnected adapters
[37] '-----------------------------
[38] Sub DisableAdapter (sName)
[39] For i = 0 To UBound(aDeviceInfo) - 1
[40] If LTrim(aDeviceInfo(i)) = "Name: " & sName Then
[41] WScript.Echo "Disabling", sName
[42] Set oExec = oWshShell.Exec(sDevcon _
[43] & " disable " & aDeviceInfo(i+2))
[44] Do
[45] WScript.Sleep 200
[46] Loop Until oExec.Status = 1
[47] End If
[48] Next
[49] End Sub
Post by JoeyThank for helping me out on this.
- The output generated by my VB Script code.
C:\software>cscript disablenics.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Local Area Connection: Media disconnected
Local Area Connection 2: Media disconnected
Local Area Connection 3: Connected
Local Area Connection 4: Media disconnected
- The output generated by ipconfig.exe /all
C:\software>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : host
Primary Dns Suffix . . . . . . . : dom.com
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : dom.com
Connection-specific DNS Suffix . : dom.com
Description . . . . . . . . . . . : Broadcom BCM5708C NetXtreme II GigE
(NDIS
VBD Client) #3
Physical Address. . . . . . . . . : 00-24-E8-6B-9A-2E
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 10.50.233.12
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . : 10.50.0.5
DHCP Server . . . . . . . . . . . : 10.50.1.201
DNS Servers . . . . . . . . . . . : 10.50.1.56
10.50.1.42
Primary WINS Server . . . . . . . : 10.50.1.201
Lease Obtained. . . . . . . . . . : Monday, August 17, 2009 5:08:03 PM
Lease Expires . . . . . . . . . . : Tuesday, August 25, 2009 5:08:03 PM
Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : Broadcom BCM5708C NetXtreme II GigE
(NDIS
VBD Client) #4
Physical Address. . . . . . . . . : 00-24-E8-6B-9A-30
Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : Broadcom BCM5708C NetXtreme II GigE
(NDIS
VBD Client) #2
Physical Address. . . . . . . . . : 00-24-E8-6B-9A-34
Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : Broadcom BCM5708C NetXtreme II GigE
(NDIS
VBD Client)
Physical Address. . . . . . . . . : 00-24-E8-6B-9A-32
C:\software>
- The input expected by netsh.exe.
I need to pass the NetconnectionID to netsh. which is Local Area
Connection, Local Area Connection 2, etc...