Reputation: 1117
I am writing a VB Script that uses WMI to determine which adapter is used for internet connectivity? For example - if I have a LAN and a 3G board it needs to tell the user which is connected. I understand that a machine might have >1 internet connection, but for now, let's assume 1.
edit: Ok, how can I do this using any command tool? Given the roaring silence, I guess this is not do-able using WMI. :-) Would trace print work? I'm not too familiar with trace.
Thanks in advance for any help! Rich
Upvotes: 2
Views: 6234
Reputation: 5087
Using Win32_NetworkAdapterConfiguration find the network device that has the lowest IPConnectionMetric, this will be the first device used for internet access.
strComputer = "."
Set objWMIService = GetObject(_
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration")
metric = 500
description = ""
For Each objItem in colItems
If (objItem.IPConnectionMetric < metric AND objItem.IPConnectionMetric >= 0) then
metric = objItem.IPConnectionMetric
description = objItem.Description
End If
Next
Set WshShell = CreateObject("WScript.Shell")
WshShell.Popup(description)
VBScript examples for accessing the WMI can be found on MSDN
Upvotes: 3