Originally posted by: mike
BOOL InternetGetConnectedState(
try using this from wininet.h/.lib
working with ie4.0+
OUT LPDWORD lpdwFlags,
IN DWORD dwReserved
);
Originally posted by: Bruce
void CHDTripsterDlg::IsInternetConnected()
RegOpenKeyEx(HKEY_CURRENT_USER,
RegQueryValueEx(hKey, "EnableAutodial", NULL, &dwDialType,
RegSetValueEx( hKey, "EnableAutodial", NULL,
pInfo = pInetSess.OpenURL("http://www.geocities.com/idbruce/bear.txt";);
if(pInfo)
catch (CInternetException* pEx)
pInetSess.Close();
RegSetValueEx( hKey, "EnableAutodial", NULL,
Let me start by saying that Ran is one smart cookie! I am a very serious researcher, and I have investigated internet connection functions. Ran provides the foundation for numerous possible utilitarian functions. The genius behind IsInternetConnected() is the temporary alteration of EnableAutodial registry setting. After altering this registry setting, you can perform numerous internet tasks without the fear of a Internet Connection dialog popping up. I have altered Ran's function to exclude registry function error checking and I have also exchanged CSocket for CInternetSession, with an inclusion of CInternetException to catch any errors.
My version of Ran's function is triggered by a 300000 millisecond timer (approx. 5 min.) which upon triggering checks for an internet connection. If a connection is established, it reads a string from an internet file and replaces an existing member variable string. I am not to keen on the CSocket class, but CInternetSession has many possibilities.
Between Ran's original function and my alteration to CInternetSession, you folks should have a hay day. Please post useful alterations so that others may use them. Remember to use CInternetException to catch the errors.
{
CStdioFile* pInfo;
CInternetSession pInetSess;
CString strNew;
HKEY hKey;
DWORD dwDial, dwDialType = REG_DWORD, dwDialSize = 4;
DWORD dwNew = 0;
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey);
(BYTE *) &dwDial, &dwDialSize );
dwDialType, (BYTE *) &dwNew, dwDialSize );
try
{
{
while(pInfo->ReadString(strNew))
{
if((lstrlen(strNew) > 0)&&
(lstrcmp(strNew, strOld) != 0))
{
strOld = strNew;
m_ctrlControl.SetText(strOld);
}
}
}
}
{
//catch WinInet errors
}
dwDialType, (BYTE *) &dwDial, dwDialSize);
RegCloseKey(hKey);
}
Originally posted by: Jeoba
If there any system callback function that can call my application with a notification message whenever the modem gets disconnected ?
ReplyOriginally posted by: L
#include "wininet.h"
if (InternetAttemptConnect(0) == ERROR_SUCCESS)
//---LINK WITH wininet.lib
{
Navigate2("www.codeguru.com",NULL,NULL);
}
else
{
LoadFromResource(IDR_START);
}
Originally posted by: Lee Gavitt
BOOL IsInternetConnection()
// Remember....A return of true doesn't guarantee a connection exists
// ReturnedFlag Could be any combo of the following
HINTERNET hInternetOpen = ::InternetOpenUrl(hInternetRoot,
return FALSE;
I tried different methods shown here and found this one to work great for me.
Mainly because I am behind a proxy and wanted to detect my connection. I believe
it will also work when not behind a proxy. If the connection doesn't exist, it is
not supposed to bring up a dial dialog.
Be sure to link in the library Wininet.lib
#include <wininet.h>
{ CString ConnectionTestPage = "http://www.somewhere.com/testpage.html";;
DWORD ReturnedFlag;
BOOL bResult = InternetGetConnectedState(&ReturnedFlag,0);
if (bResult != FALSE)
{ // Go ahead and try to read the test page. If we get it, then we are connected.
// Otherwise we are not.
// INTERNET_CONNECTION_CONFIGURED
// Local system has a valid connection to the Internet,
// but it may or may not be currently connected.
// INTERNET_CONNECTION_LAN
// Local system uses a local area network to connect to the Internet.
// INTERNET_CONNECTION_MODEM
// Local system uses a modem to connect to the Internet.
// INTERNET_CONNECTION_MODEM_BUSY
// No longer used.
// INTERNET_CONNECTION_OFFLINE
// Local system is in offline mode.
// INTERNET_CONNECTION_PROXY
// Local system uses a proxy server to connect to the Internet.
// INTERNET_RAS_INSTALLED
// Local system has RAS installed.
//Attempt connection
HINTERNET hInternetRoot = InternetOpen("My AppName",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0);
ConnectionTestPage,
NULL,
0,
INTERNET_FLAG_RELOAD,
0);
if (hInternetOpen != NULL)
{ // We're connected!!!
::InternetCloseHandle(hInternetOpen);
::InternetCloseHandle(hInternetRoot);
return TRUE;
}
::InternetCloseHandle(hInternetRoot);
}
}
Originally posted by: Edwin Eefting
Isn't it sad that there are millions of api's, but there not one that does the trick?
Well, mayby you can check the routing tables to see if there is at least a _route_ to the internet. (do a "route print" at your dosprompt if you don't know what this is)
Windows add's these routes dynamicly when a dialupconnection is esstablished. So when there is a default route (0.0.0.0) to a gateway, you know there's either an active dialup connection or a direct-lan connection. After that you can use any means to determine if there really is a connection, without triggering the dialup box etc. (like the ping-method)
I didn't write any code to do this, but mayby i will sooner or later. I will need it in my program to check for updates and stuff.
(look at www.lazypeople.net)
Reply
Originally posted by: SusChem
i can't find the downloadable source code?pls help......
Originally posted by: Wiebe
Anyone thought about the InternetGetConnectedState Function?
(Retrieves the connected state of the local system.)
Does anybody know the difference between this one and
InternetCheckConnection? The Help info about
InternetCheckConnection does not make sense to me.
The description and return value do not fit.
So InternetGetConnectedState makes more sense to me.
BTW
InternetGetConnectedState also does not check connection
via LAN correctly.
Wiebe
Reply
Originally posted by: Jarek
In Get hostname and ip address of local computer by Jeff Lundgren, he makes it easy for everyone to just do a simple loopback and check for the IP.
If the IP is 127.0.0.1 the user is not online! else he is. This way to determine a internet connection is maybe best for modem user and DHCP user.
Jarek Gibek
ReplyOriginally posted by: Dmitry Devyatkin
1. I a have modem and LAN on Windows 2000. I don't dialup connection. In function connect i a specified no valid address (for example www.Mmicrosoft.com). Call this function and recive dialup connection dialog.
2. How to determine whether is accessible(exists) html page on site. Site at time is accessible.
How to solve problem?
Thanks,
Hi!
Since I've been long looking for a similar solution, I found your examle very useful.
Help me please!
Dima