Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to get connection speed using C#

0 views
Skip to first unread message

jianpingjimpaul

unread,
Dec 25, 2002, 5:29:04 PM12/25/02
to
It seems that I can get the speed using VB as shown below. I would
like to know how to obtain the same information with C#. Your help is
greatly appreciated!

==========================================================
Dim locator = CreateObject("WbemScripting.SWbemLocator")

Dim Cim = locator.ConnectServer("", "root/cimv2")

Dim wmi = locator.ConnectServer("", "root/wmi")

Dim WQL = "Select * From Win32_NetworkAdapterConfiguration
Where DatabasePath IS NOT NULL"

Dim NetworkAdapters = Cim.ExecQuery(WQL)
Dim Adapter As Object
For Each Adapter In NetworkAdapters
Dim cap = Adapter.Caption
Dim prop = "MSNdis_LinkSpeed='" & Mid(cap, InStr(cap, "]")
+ 2) & "'"
Dim LinkInfo = wmi.Get(prop)
MsgBox(LinkInfo.NdisLinkSpeed)
Next

Chung-Wei Foong [MSFT]

unread,
Jan 2, 2003, 12:24:15 PM1/2/03
to
The following is a sample:

// Sample for LinkSpeed Retrieval

// Specify the namespace that you will like to obtain NdisLinkSpeed
ManagementScope scope = new ManagementScope("\\\\.\\root\\wmi");

// Note: The default namespace in ManagementScope is root\cimv2
SelectQuery query = new SelectQuery("Select * From
Win32_NetworkAdapterConfiguration Where DatabasePath IS NOT NULL");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

foreach (ManagementObject o in searcher.Get()) {
// You will need to find or write your own Mid() function for your string
operations.
String Network_InstanceName = o["Caption"].ToString().Substring(11);
Console.WriteLine(Network_InstanceName);

SelectQuery queryClass = new SelectQuery("Select * from MSNdis_LinkSpeed
where InstanceName = '" + Network_InstanceName + "'");

ManagementObjectSearcher s = new ManagementObjectSearcher(queryClass);
// Set namespace as defined above
s.Scope = scope;
ManagementPath Path = new
ManagementPath(string.Format("MSNdis_LinkSpeed.InstanceName='{0}'",
Network_InstanceName));
ManagementObject obj = new ManagementObject(scope,Path,null);
// Display results to console
Console.WriteLine("Name of the Instance: {0}", obj["InstanceName"]);
Console.WriteLine("LinkSpeed is : {0}", obj["NdisLinkSpeed"]);
}

This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"jianpingjimpaul" <jr...@novus-tele.net> wrote in message
news:ed9147b8.02122...@posting.google.com...

0 new messages