简体   繁体   中英

Detecting a 3G connection in Windows 7 and 8 in a desktop application

I am in the process of developing a cloud backup software. The application is a desktop application developed using C#.

I need to add an option to stop/pause the backup if the computer was connected to a 3G network to save cost for the user.

I cannot seem to be able to find any example on how this can be achieved, there are some examples for Windows Phone and Windows Store Apps but I cannot find anything that can check if the connection type is a WiFi/Ethernet or 3G the latter is my main concern.

I tried a test application to enumerate the networks:

Console.WriteLine("checking network interfaces\n");

NetworkInterface[] interfaces =  NetworkInterface.GetAllNetworkInterfaces();

foreach (var networkInterface in interfaces)
{
   Console.WriteLine("Interface Detected");
   Console.WriteLine("Description: "+networkInterface.Description);
   Console.WriteLine("ID: " + networkInterface.Id);
   Console.WriteLine("Name: " + networkInterface.Name);
   Console.WriteLine("Interface Type: " + networkInterface.NetworkInterfaceType);
   Console.WriteLine("Operational Status: " + networkInterface.OperationalStatus.ToString());
   Console.WriteLine("Speed: " + networkInterface.Speed.ToString());
   Console.WriteLine("Supports Multicast: " + networkInterface.SupportsMulticast.ToString());
   Console.WriteLine("#########################################################\n");
}

The above code list my 3G connection as PPP which can be either ADSL or 3G. I am not sure if I can differentiate using some other options or APIs

I need a clear way to distinguish between those networks and so far I cannot find a way of doing so.

Can someone please help?

Use the native WiFi functions to get WiFi interfaces (WlanEnumInterfaces), and Mobile Broadband API to get 3G interfaces (IMbnInterfaceManager.GetInterfaces). Newer 3G modems should support Mobile Broadband API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM