一个代号为“mystifeid”的神秘人在这个网站上解决了这个难题,第三个帖子下来:
http ://social.msdn.microsoft.com/Forums/uk-UA/scripting/thread/e3936dff-7395-4a6a-ab35-aa1aab0bcd71
这是他们可爱的代码:
Dim strQuery, strQuery2, objLocator, objWMI, objItem, objItem2, colItems, colItems2, resultString, nicName
strQuery = "SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface"
strQuery2 = "SELECT * FROM Win32_NetworkAdapter"
Set objLocator = CreateObject( "WbemScripting.SWbemLocator" )
Set objWMI = objLocator.ConnectServer( ".", "root\CIMV2" )
objWMI.Security_.ImpersonationLevel = 3
Set colItems2 = objWMI.ExecQuery( strQuery2, "WQL", 0 )
Set colItems = objWMI.ExecQuery( strQuery, "WQL", 0 )
resultString = ""
For Each objItem2 In colItems2
If objItem2.NetConnectionStatus = 2 Then
nicName = Mid(objItem2.Name, 1, 5)
resultString = resultString & "Adapter Name : " & objItem2.Name & VbCrLf
resultString = resultString & "MAC Address : " & objItem2.MACAddress & VbCrLf
For Each objItem In colItems
If Mid(objItem.Name, 1, 5) = nicName Then
resultString = resultString & "CurrentBandwidth : " & objItem.CurrentBandwidth & VbCrLf
End If
Next
End If
Next
Set objLocator = Nothing
Set objWMI = Nothing
Set colItems = Nothing
Set colItems2 = Nothing
WScript.Echo resultString
PS-我很快就会对 Win7 和 Win2008 进行审查,并让大家知道。