Mega Code Archive

 
Categories / Delphi / Examples
 

Quiet online checking

Title: "Quiet" online checking Question: Answer: Sometimes it's required to check if a user has an active Internet connection, but you don't want the DUN dialog box to popup by your code. Well, it was not easy to find out a method for that, but finally a hint by Henri Fournier in the Newsgroups gave me the idea for the following 2 powerful lines: USES WinInet; .. .. function InternetConnected: Boolean; CONST // local system uses a modem to connect to the Internet. INTERNET_CONNECTION_MODEM = 1; // local system uses a local area network to connect to the Internet. INTERNET_CONNECTION_LAN = 2; // local system uses a proxy server to connect to the Internet. INTERNET_CONNECTION_PROXY = 4; // local system's modem is busy with a non-Internet connection. INTERNET_CONNECTION_MODEM_BUSY = 8; VAR dwConnectionTypes : DWORD; BEGIN dwConnectionTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY; Result := InternetGetConnectedState(@dwConnectionTypes,0); END; That's all! Have fun.. Note from 05-Dec-98: I had to find that this solution only works under Windows 95/98 - Since the required DLL routine doesn't seem to be implemented by Windows NT, this OS produces an error during program startup when you refer to Wininet. If anyone knows a better method to do Online-Checks, please let me know!