Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

online/offline status

Status
Not open for further replies.

Detective

Programmer
Mar 8, 2002
15
NL
How to show the online/offline status
using wininet? I tried
INTERNET_STATUS_CONNECTED_TO_SERVER
but it always returns 21, even if you
aren't online.
 
Detective,

After a great deal of research, it appears this isn't something that's trivial to do, as much depends on the version of Windows, the version of IE, the type of connection used to access the Internet and (to some degree) the phase of the moon. (OK, that last one is a bit of a joke...but only a bit.)

For a brief overview of the difficulties, please see FAQ 6.7 on
Some of the tidbits I picked up while digging this up:

-- MS Reportedly suggests your problem may be occurring because you're not using IE as your default browser (
-- MS apparently wants us using IsNetworkAlive ( however, a) that requires IE 5.5 or later to be installed and b) I cannot find any Borland-supplied wrappers for the SensAPI DLL they refer to, not even in Delphi 6 (Pro), SP2--not even on JEDI.

-- I did find a VB example using it ( however, I simply ran out of time while running down the other information. I'll leave adapting is as an exercise. :)

-- There does appear to be at least one component ( that claims to implement this properly, but I've not used it. They're licensing seem straightforward, unless you plan to sell commercial licenses. (At least that's how I understood their terms.) If you're not sure if I read that correctly, then you should probably send them an email asking for clarification.

Hope this helps...

-- Lance
 
Thanx Lance,

but all these examples apply to MS Visual Basic.
They don't work with Delphi! So if anyone knows
how to show the online/offline status,
please reply!
 
Detective,

The examples can be easily adapted to Delphi. In fact, it's a useful skill to learn, since new API functionality is frequently documented using VB and/or VC before it's documented with Delphi.

I did do some of this work on my machine (which uses a LAN connection to a DSL connection), however, I kept getting bad results. It kept reporting that I was connected, even when I specifically deactivated the connection to the Internet at the router.

That's why I didn't post the code, as it doesn't really solve the problem you asked in my environment and there's no information available about why that could be the case, other than the frequently encountered "this doesn't always work as expected."

Unforunately, I do not have the resources to test the various possibilities (e.g. a dial-up connection using a modem, a proxy connection, AOL, etc.

However, you're certainly welcome to try the following code to see if it works in your situation:

Code:
procedure TForm1.Button3Click(Sender: TObject);
var
   strResult : String;
   strType   : String;
   dwFlags   : DWORD;

const
   INTERNET_RAS_INSTALLED = 16;
   INTERNET_CONNECTION_OFFLINE = 32;
   INTERNET_CONNECTION_CONFIGURED = 64;

function Check( dwFlags : DWORD; dwCheck : DWORD ) : Boolean;
begin
   result := ( dwFlags AND dwCheck ) = dwCheck;
end;

begin

   dwFlags := INTERNET_CONNECTION_OFFLINE;
   if InternetGetConnectedState( @dwFlags, 0 ) then
      strResult := 'are'
   else
      strResult := 'aren''t';

   strType := '';
   if check( dwFlags, INTERNET_CONNECTION_CONFIGURED ) then
      strType := strType + 'is configured' + #10;

   if check( dwFlags, INTERNET_CONNECTION_OFFLINE ) then
      strType := strType + 'offline' + #10;

   if check( dwFlags, INTERNET_RAS_INSTALLED ) then
      strType := strType + 'RAS is installed' + #10;

   if check( dwFlags, INTERNET_CONNECTION_LAN ) then
      strType := strType + 'Connection through a LAN' + #10;

   if check( dwFlags, INTERNET_CONNECTION_PROXY ) then
      strType := strType + 'Using a proxy server' + #10;

   showMessageFmt( 'Windows says you %s ' +
                   'connected to the Internet.' + #10#10 +
                   'Connection details: ' + #10 + '%s',
                   [ strResult, strType ] );

end;

Again, this doesn't really work. It compiles and appears to run correctly, however, it returns invalid results. (It says I'm connected when I'm not.) Thus, I think there's more to the problem.

I did try other techniques, however, I ran into similar results. I will keep working on the problem and will post an article to the website if I manage to crack this nut.

Naturally, if anyone else has insights, I (for one) would love to hear them.

Hope this helps...

-- Lance
 
One possible reason your code showed that you were connected to the internet is maybe you were. If other machines on your LAN talk TCP/IP, then as far as your machine is concerned, you're connected to the internet. OK, it's an internet of 10 machines, not 10 million, but how is Windows to know that?

You might get different results if you disconnect the ethernet cable from the back of your machine and reboot; or if you attach to a LAN that only contains, for example, IPX/SPX packets.

On a related note, I have a UDP broadcast program that I use to broadcast on a particular UDP port using Windows sockets, and a matching program that listens on the same port. The two programs will communicate just fine between two different machines, and they'll work just fine when both run on the same machine, too, provided that there is a network of some kind connected to that machine. If there's no network, Windows UDP refuses to broadcast. -- Doug Burbidge mailto:doug@ultrazone.com
 
Hi-

I have tried to establish online status myself just recently and come across the problems mentioned here.

I connect to the Internet over a LAN (which Windows can accurately report) but no api calls can accrurately detect my actual online status.

Eventually I came to the conclusion that the only way to determine your online status is to ping an IP address that is external to the network your on and check the results.

Sounds like hard work I know - but I have found it the most effective. I suggest you use a reliable IP address also (something you know will be online .) To ping the actual IP - I used a component I found at Sorry I dont have specific reference for it - but do a search on "ping" on that site and you should find it ok.

Opp.
 
OK Lance,
I tried your example, but
when I run it, Delphi (version 3.0 build 5.53)
says: "undeclared identifier: Internetgetconnectedstate"
"undeclared identifier: INTERNET_CONNECTION_LAN"
"undeclared identifier: INTERNET_CONNECTION_PROXY"
Yes, I included "uses wininet;", but Delphi keeps
generating error messages!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top