如何检测NIC生成的以太网连接类型?也就是说,我的NIC是一个千兆以太网设备,但由于它是自动感应的,它可能以千兆速度或快速以太网速度连接。
如何找出连接的速度?
我尝试使用WMI的Win32_NetworkAdapter
,CIM_NetworkAdapter
,甚至是wmic NET get Name,Speed
,但所有这些都为“速度”返回空白。
顺便说一句,我正在使用Windows XP Pro SP3。但我想要一个适用于Windows Server 2003(标准版和企业版),Windows Server 2008和Windows Server 2008 R2的解决方案。
答案 0 :(得分:1)
一个代号为“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进行审查,让所有人知道。