The internetgetconnectedstate function returns the network connection status of the local system.
Syntax:
Bool internetgetconnectedstate (_ out lpdword lpdwflags ,__ in DWORD dwreserved); parameter:
Lpdwflags[Out] Point to a variable that receives the connection description. This parameter can still return a valid flag when the function returns flase. This parameter can be one or more of the following values.
value |
meaning |
internet_connection_configured0x40 |
local system has a valid connection to the Internet, but it might or might not be currently connected. |
internet_connection_lan 0x02 |
local system uses a local area network to connect to the Internet. |
internet_connection_modem0x01 |
local system uses a modem to connect to the Internet. |
internet_connection_modem_busy0x08 |
no longer used. |
internet_connection_offline 0x20 |
local system is in offline mode. |
internet_connection_proxy0x04 |
local system uses a proxy server to connect to the Internet. |
internet_ras_installed0x10 |
local system has Ras installed. |
Dwreserved[In] Reserved value. It must be 0. Return Value: If a modem or LAN connection exists, true is returned. If no Internet connection exists or all connections are not activated, false is returned. When this function returns false, Program Yes
Getlasterror To receive errors Code . Example:
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; using system. runtime. interopservices; namespace consoleapplication1 {class program {private const int internet_connection_modem = 1; private const int internet_connection_lan = 2; private const int internet_connection_proxy = 4; private const int Limit = 8; ORT ("wininet. DLL ")] // declare an external function: Private Static extern bool internetgetconnectedstate (ref int flag, int dwreserved); static void main (string [] ARGs) {int flag = 0; string netstates = ""; if (! Internetgetconnectedstate (ref flag, 0) {console. writeline ("No! ");} Else {If (flag & internet_connection_modem )! = 0) netstates + = "connect by modem/N"; if (flag & internet_connection_lan )! = 0) netstates + = "connect by LAN/N"; if (flag & internet_connection_proxy )! = 0) netstates + = "connect by proxy/N"; if (flag & internet_connection_modem_busy )! = 0) netstates + = "modem is busy/N";} console. writeline (netstates); console. Readline ();}}}
: