Win32 API functions:
Function to be used: internetgetconnectedstate
Function prototype: bool internetgetconnectedstate (lpdword lpdwflags, DWORD dwreserved );
The parameter lpdwflags returns the current network status. The parameter dwreserved is still a reserved parameter. Set it to 0.
Internet_connection_modem connects to the network through the modem
Internet_connection_lan
This function is very powerful. It can:
1. Determine whether the network connection is through the NIC or by adjusting the modem
2. Whether to access the Internet through proxy
3. Determine whether the connection is on line or off line.
4. Determine whether to install the "Dial-Up Network Service"
5. Check whether the modem is in use
This Win32 API is in wininet. dll in the System32 folder.
To use this judgment, you need to write it like this in the class:
Private const int internet_connection_modem = 1;
Private const int internet_connection_lan = 2;
[Dllimport ("wininet. dll")]
Private Static extern bool internetgetconnectedstate (
Ref int dwflag,
Int dwreserved
);
// Call the method (for example, put a button in winform and click it ):
Private void button#click (Object sender, system. eventargs e ){
System. int32 dwflag = new int ();
If (! Internetgetconnectedstate (ref dwflag, 0 ))
MessageBox. Show ("No network connection! ");
Else
If (dwflag & internet_connection_modem )! = 0)
MessageBox. Show ("Use a modem to access the Internet. ");
Else
If (dwflag & internet_connection_lan )! = 0)
MessageBox. Show ("use the network card to access the Internet. ");
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service