2012-10-30 70 views
3

如何檢測我的NIC生成的以太網連接類型?也就是說,我的網卡是千兆以太網設備,但由於它是自動感應的,因此它可能以千兆位速度或快速以太網速度連接。在Windows上以編程方式檢測連接的網絡速度

我該如何找出連接速度?

我試過使用WMI的Win32_NetworkAdapter,CIM_NetworkAdapter,甚至wmic NET get Name,Speed,但它們都是空白的速度。順便說一句,我正在使用Windows XP Pro SP3。但我想要一個適用於Windows Server 2003(Standard & Enterprise),Windows Server 2008和Windows Server 2008 R2的解決方案。

+1

第三篇文章在此鏈接中有適用於XP的VBScript:http://social.msdn.microsoft.com/Forums/uk-UA/scripting/thread/e3936dff-7395-4a6a-ab35-aa1aab0bcd71 – Lizz

+0

@莉絲謝謝你!有用!現在,如果你可以發表你的評論作爲答案,我將它標記爲* * *答案儘快:) – pepoluan

+0

很高興它幫助! :) – Lizz

回答

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很快就讓大家知道了。

+0

它也適用於Win7和Win2008,...太好了! – pepoluan

相關問題