Bandwidth
How can i have these items in my c# project?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 20, 2011, 1:20 PM
However, this only tells you the type of connection (LAN, Modem etc) together with the connection name so if you need to correlate this with the network adapter then some more work will be needed.
As far as getting all possible network adapters that could be used for internet access is concerned, I think you'll have to be content with getting all the enabled adapters and, unless you have some other way of filtering them, disable them all.
Here's some code to do all this:
Incidentally, there is another WMI class called Win32_NetworkAdapterConfiguration (http://msdn.microsoft.com/en-us/library/windows/desktop/aa394217(v=vs.85).aspx) which contains some further useful information about network adapters. If there are some enabled adapters that you don't want to disable because they're never used for internet access, then you might be able to identify them from that class and then relate them back to the Win32_NetworkAdapter class using the InterfaceIndex property.
VulpesPosted Dec 6, 2011, 11:17 AM
abc sharpPosted Dec 6, 2011, 10:48 AM
first of all go the below address(maybe you can't access this area):
IE->tools menu->Internet options->connections tab->setting of dial-up and virtual private->
1)check the automatically detect settings from automatic configuration part and see its address in registry:
HKEY_CURRENT_USER\software\microsoft\windows\current version\internet settings\connections\
save value of Nokia E52 USB Modem (OTA) type ,i used below code for that:
RegistryKey rk2 = Registry.CurrentUser.CreateSubKey(@"software\microsoft\windows\currentversion\internet settings\connections");
rk2.SetValue("Nokia E52 USB Modem (OTA)",
new byte[] {0x46,0x00,0x00,0x00,0xCE,0x00,0x00,0x00,
09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x05,0x00,0x00,0x00,0x6C,0x6F,0x63,0x61,
0x6C,0x00,0x00,0x00,0x00,0x05,0x00,0x00,
00,0x00,0x00,0x00,0x00,0x40,0xE7,0x1B,
0x50,0x49,0xB4,0xCC,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x00,0x00,0x00,0x17,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFE,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x34,0xA8,0x13,
0x4B,0xF5,0xFA,0xE7,0x1B,0x12,0x00,0x00,
0x00,0xBC,0x7D,0x00,0x00,0xD0,0x7D,0x00,
0x00,0xE8,0x7D,0x00,0x00,0xFC,0x7D,0x00,
0x00,0x18,0x7E,0x00,0x00,0x9C,0x81,0x00,
0x00,0x5C,0x80,0x00,0x00,0x74,0x80,0x00,
0x00,0x90,0x80,0x00,0x00,0x3C,0x80,0x00,
0x00,0x98,0x83,0x00,0x00,0x08,0x8E,0x00,
0x00,0x24,0x8E,0x00,0x00,0x98,0x8E,0x00,
0x00,0xB8,0x8E,0x00,0x00,0x04,0x8F,0x00,
0x00,0x18,0x8F,0x00,0x00,0x34,0x8F,0x00,
0x00,0x4C,0x8F,0x00,0x00,0x64,0x8F,0x00,
0x00,0x80,0x8F,0x00,0x00,0x38,0x8E,0x00,
0x00,0x50,0x8E,0x00,0x00,0x98,0x8F,0x00,
0x00,0x68,0x8E,0x00,0x00,0x02,0x00,0x00,
0x00,0x0A,0x05,0x18,0xE4,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x78,0xBB,0x00,
0x00,0xF4,0xDA,0x00,0x00,0x08,0xDB,0x00,
0x00,0x1C,0xDB,0x00,0x00,0x60,0x00,0x00,
0x00,0x78,0x00,0x00,0x00,0x30,0x7D,0xF4,
0x66,0x7C,0x00,0x00,0x80,0x14,0x00,0x00,
0x00,0x18,0x00,0x00,0x00,0x30,0x00,0x00,
0x00,0x48,0x00,0x00,0x00,0x60,0x00,0x00,
0x00,0x78,0x00,0x00,0x00,0x90,0x00,0x00,
0x00,0xA8,0x00,0x00,0x00,0xC0,0x00,0x00,
0x00,0xD8,0x00,0x00,0x00,0xF0,0x00,0x00,
0x00,0x08,0x01,0x00,0x00,0x20,0x01,0x00,
0x00,0x38,0x01,0x00,0x00,0x50,0x01,0x00,
0x00,0x68,0x01,0x00,0x00,0x80,0x01,0x00,
0x00,0x98,0x01,0x00,0x00,0xB0,0x01,0x00,
0x00,0xC8,0x01,0x00,0x00,0x17,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x01,0x00,
0x00,0x41,0x37,0x9E,0x76,0x34,0xA8,0x13,
0x4B,0xF5,0xFA,0xE7,0x1B,0x00,0x00,0x00,
0x00,0x88,0x02,0x00,0x00,0xA0,0x02,0x00,
0x00,0xB8,0x02,0x00,0x00,0xD0,0x02,0x00,
0x00,0xE8,0x02,0x00,0x00,0x00,0x03,0x00,
0x00,0x18,0x03,0x00,0x00,0x30,0x03,0x00,
0x00,0x48,0x03,0x00,0x00,0x60,0x03,0x00,
0x00,0x78,0x03,0x00,0x00,0xBE,0x62,0xF4,
0x66,0x7C,0x03,0x00,0x80,0x47,0x00,0x00,
0x00,0xD8,0x03,0x00,0x00,0xF0,0x03,0x00,
0x00,0x08,0x04,0x00,0x00,0x20,0x04,0x00,
0x00,0x38,0x04,0x00,0x00,0x50,0x04,0x00,
0x00,0x68,0x04,0x00,0x00,0x80,0x04,0x00,
0x00,0x98,0x04,0x00,0x00,0xB0,0x04,0x00,
0x00,0xCB,0x04,0x00,0x00 } , RegistryValueKind.Binary);
System.Windows.MessageBox.Show("The Internet Has Been Connected!");
}
2)uncheck above item and check "use a proxy server ... " from proxy part and see again the amount of that type and save it like :
RegistryKey rk2 = Registry.CurrentUser.CreateSubKey(@"software\microsoft\windows\currentversion\internet settings\connections");
rk2.SetValue("Nokia E52 USB Modem (OTA)",
new byte[] {0x46,0x00,0x00,0x00,0xcc,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,
0x31,0x32,0x37,0x2E,0x30,0x2E,0x30,0x2E,
0x31,0x3A,0x32,0x30,0x05,0x00,0x00,0x00,
0x6C,0x6F,0x63,0x61,0x6C,0x00,0x00,0x00,
0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0x1A,0x77,0x87,0x43,0xB4,0xCC,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
0x00,0x17,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFE,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x34,0xA8,0x13,0x4B,0xF5,0xFA,0xE7,
0x1B,0x12,0x00,0x00,0x00,0xBC,0x7D,0x00,
0x00,0xD0,0x7D,0x00,0x00,0xE8,0x7D,0x00,
0x00,0xFC,0x7D,0x00,0x00,0x18,0x7E,0x00,
0x00,0x9C,0x81,0x00,0x00,0x5C,0x80,0x00,
0x00,0x74,0x80,0x00,0x00,0x90,0x80,0x00,
0x00,0x3C,0x80,0x00,0x00,0x98,0x83,0x00,
0x00,0x08,0x8E,0x00,0x00,0x24,0x8E,0x00,
0x00,0x98,0x8E,0x00,0x00,0xB8,0x8E,0x00,
0x00,0x04,0x8F,0x00,0x00,0x18,0x8F,0x00,
0x00,0x34,0x8F,0x00,0x00,0x4C,0x8F,0x00,
0x00,0x64,0x8F,0x00,0x00,0x80,0x8F,0x00,
0x00,0x38,0x8E,0x00,0x00,0x50,0x8E,0x00,
0x00,0x98,0x8f,0x00,0x00,0x68,0x8E,0x00,
0x00,0x02,0x00,0x00,0x00,0x0A,0x05,0x18,
0xE4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x78,0xBB,0x00,0x00,0xF4,0xDA,0x00,
0x00,0x08,0xDB,0x00,0x00,0x1C,0xDB,0x00,
0x00,0x60,0x00,0x00,0x00,0x78,0x00,0x00,
0x00,0x30,0x7D,0xF4,0x66,0x7C,0x00,0x00,
0x80,0x14,0x00,0x00,0x00,0x18,0x00,0x00,
0x00,0x30,0x00,0x00,0x00,0x48,0x00,0x00,
0x00,0x60,0x00,0x00,0x00,0x78,0x00,0x00,
0x00,0x90,0x00,0x00,0x00,0xA8,0x00,0x00,
0x00,0xC0,0x00,0x00,0x00,0xD8,0x00,0x00,
0x00,0xF0,0x00,0x00,0x00,0x08,0x01,0x00,
0x00,0x20,0x01,0x00,0x00,0x38,0x01,0x00,
0x00,0x50,0x01,0x00,0x00,0x68,0x01,0x00,
0x00,0x80,0x01,0x00,0x00,0x98,0x01,0x00,
0x00,0xB0,0x01,0x00,0x00,0xC8,0x01,0x00,
0x00,0x17,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x01,0x00,0x00,0x41,0x37,0x9E,
0x76,0x34,0xA8,0x13,0x4B,0xF5,0xFA,0xE7,
0x1B,0x00,0x00,0x00,0x00,0x88,0x02,0x00,
0x00,0xA0,0x02,0x00,0x00,0xB8,0x02,0x00,
0x00,0xD0,0x02,0x00,0x00,0xE8,0x02,0x00,
0x00,0x00,0x03,0x00,0x00,0x18,0x03,0x00,
0x00,0x30,0x03,0x00,0x00,0x48,0x03,0x00,
0x00,0x60,0x03,0x00,0x00,0x78,0x03,0x00,
0x00,0xBE,0x62,0xF4,0x66,0x7C,0x03,0x00,
0x80,0x47,0x00,0x00,0x00,0xD8,0x03,0x00,
0x00,0xF0,0x03,0x00,0x00,0x08,0x04,0x00,
0x00,0x20,0x04,0x00,0x00,0x38,0x04,0x00,
0x00,0x50,0x04,0x00,0x00,0x68,0x04,0x00,
0x00,0x80,0x04,0x00,0x00,0x98,0x04,0x00,
0x00,0xB0,0x04,0x00,0x00,0xC8,0x04,0x00
}, RegistryValueKind.Binary);
System.Windows.MessageBox.Show("The Internet Has Been DisConnected!");
}
so i can put these codes in a button , when i click on the connect button i can use the internet and when i click on the disconnect button i can't access to the internet .
thank you for your effort and i hope it useful.
abc sharpPosted Nov 27, 2011, 12:09 PM
please download Cyber sieve software it works for all kind of adapters with just a check box.i want just that.
VulpesPosted Nov 27, 2011, 10:13 AM
abc sharpPosted Nov 26, 2011, 4:06 PM
VulpesPosted Nov 26, 2011, 1:22 PM
It's just possible that the name (as far as netsh is concerned) is slightly different.
I'd try the following command to list all registered interfaces:
netsh interface show interface
abc sharpPosted Nov 26, 2011, 9:36 AM
VulpesPosted Nov 26, 2011, 8:41 AM
abc sharpPosted Nov 26, 2011, 12:43 AM
VulpesPosted Nov 25, 2011, 6:34 PM
abc sharpPosted Nov 25, 2011, 2:24 PM
abc sharpPosted Nov 24, 2011, 12:55 PM
see my picture:
VulpesPosted Nov 24, 2011, 12:21 PM
Regarding your own suggestion, I imagine you must be talking about the Tools menu of Internet Explorer but, unfortunately, the Settings button is disabled on mine and so I couldn't get into it to see exactly what you're talking about. However, trying to do anything like that programatically would be extremely difficult.
abc sharpPosted Nov 24, 2011, 1:15 AM
I have an another idea .go to Tools menu-Internet Options-Connection tab-Dial up and virtual private and network settings section -settings- 1)uncheck the item of Automatically... and 2)checked use a proxy server section and use a address and a port.if we find this in registry we can do it another way.
What's your opinion?
VulpesPosted Nov 23, 2011, 3:45 PM
The code in your last post is just another variation of the WMI code to get all network adapters and to disable the one with a particular name. There's no way that the code on its own can tell you what the active connection is.
abc sharpPosted Nov 23, 2011, 1:44 AM
using System;
using System.Collections.Generic;
using System.Management;
namespace NetworkAdapterInfo
{
class Program
{
static void Main(string[] args)
{
// Query the WMI for class Win32_NetworkAdapter
//
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"select * from Win32_NetworkAdapter"))
{
// Get the result set
//
ManagementObjectCollection results = searcher.Get();
// Disable all network adapters :-O
//
foreach (ManagementObject obj in results)
{
System.Console.WriteLine("Found adapter {0} :", obj["name"]);
if (obj["name"].ToString() == "Your connection name")
{
System.Console.WriteLine("Disabling adapter ...");
obj.InvokeMethod("Disable", null);
System.Console.WriteLine("Done.");
}
}
Console.ReadLine();
}
}
}
}
this give me all of my adapters but i don't know which one is active connection? when i use one adapter for check it shows me an error on this line :
obj.InvokeMethod("Disable", null);
Do you have an idea?
abc sharpPosted Nov 23, 2011, 12:57 AM
in fact doesn't run foreach(sarch variable is empty).what's the problem?
VulpesPosted Nov 22, 2011, 9:11 AM
With reference to the earlier code, were you in fact expecting the 'active' connection to be Nokia E52 USB Modem (0TA)?
abc sharpPosted Nov 22, 2011, 9:03 AM
VulpesPosted Nov 22, 2011, 6:24 AM
VulpesPosted Nov 21, 2011, 2:38 PM
abc sharpPosted Nov 21, 2011, 1:29 PM
SelectQuery query = new SelectQuery("Win32_NetworkAdapter");
ManagementObjectSearcher search = new ManagementObjectSearcher(query);
string text = "The following adapter types are present";
foreach (ManagementObject result in search.Get())
{
NetworkAdapter adapter = new NetworkAdapter(result);
text += adapter.AdapterType + "\r\n";
}
MessageBox.Show(text);
some adapter at the first also is empty (why).and my active connection is usb modem(mobile).
VulpesPosted Nov 21, 2011, 9:16 AM
If you're happy that you can identify all the adapters that need to be disabled from that, then you can just call the Disable() method on them from the code you had to start with.
abc sharpPosted Nov 21, 2011, 2:53 AM
you mean can not disconnect the active connection ?if would be true all of my effort is vain.
abc sharpPosted Nov 20, 2011, 3:08 AM
my program show all of information such as sent data and received data and i want when i define an especial amount for example 10 Mb for a day when sum of sent data and received to be 10Mb disconnect automatically the internet (i used for this , WMI class).
but i have a problem ,i want get all connections that i have and disable all of them if not just get one active connection that has connected me to the internet.
see my picture . How can i do that?? Can you help me??
excuse me when i upload image with "upload imege to site" i can't see my picture.
Mahesh ChandPosted Nov 19, 2011, 1:30 PM
abc - Can you describe your questions in more details? Also, can you change your name to your real name.
Also, this post could be a good Article or blog.
abc sharpPosted Nov 19, 2011, 10:07 AM
And my last question:
which one is my active connection and how can i disable the internet?
VulpesPosted Nov 19, 2011, 8:22 AM
abc sharpPosted Nov 19, 2011, 12:29 AM
SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
I think write anoher amount for "NetConnectionStatus=2" i don't know exactly??
VulpesPosted Nov 18, 2011, 2:27 PM
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx
I'd imagine that "wireless" would be the one that you'd want. However, you could get a list of all adapter types using this code:
Incidentally, the Disable method only works on Vista, Windows 7 and Windows Server 2008 so I assume you have one of those.
abc sharpPosted Nov 18, 2011, 10:39 AM
abc sharpPosted Nov 17, 2011, 6:00 PM
using ROOT.CIMV2.Win32;
at th top of form1.cs and it worked.
but when i run my program it doesn't disable ,actually quary variable is empty.so i have two problems else:
1) why identifier adapter to be empty?(don't have any connections)
2) how can i disable my usb adapter?(i use usb mobile connection)
I changed place code to form1.cs but didn't work again.
VulpesPosted Nov 16, 2011, 11:42 AM
However, you look to me to be putting the button1_Click handler inside networkadapter.cs which could produce a stack overflow when you try to create a new NetworkAdapter object.
This method should instead be placed in Form1.cs and should be added in the normal way i.e. double click button1 in the VS designer and then paste the code into the skeleton handler. If you do that, then the event will automatically be wired up for you.
abc sharpPosted Nov 16, 2011, 11:09 AM
VulpesPosted Nov 16, 2011, 8:57 AM
You also need to add a reference to System.Management.dll to your project so that you can use the WMI classes.
So, assuming you've done all this, are you saying that it's not working?
abc sharpPosted Nov 15, 2011, 3:24 PM
I found this :
http://blog.opennetcf.com/ncowburn/2008/06/24/HOWTODisableEnableNetworkConnectionsProgrammaticallyUnderVista.aspx
and i downloded sdk from:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=15354
and i created NetworkAdapter.cs and added to my project but i can't add this file to System.Management.dll because i can't use NetworkAdapter.cs .what can i do?
VulpesPosted Nov 12, 2011, 5:17 PM
What aspect is giving you difficulty?
abc sharpPosted Nov 12, 2011, 9:37 AM
VulpesPosted Nov 10, 2011, 11:50 AM
http://www.m0interactive.com/archives/2008/02/06/how_to_calculate_network_bandwidth_speed_in_c_/