Solved

Programatically testing if a computer is connected to a DUN connection

Posted on 2001-06-27
4
147 Views
Last Modified: 2010-04-06
I need a function which will work on Win9x and WinNT/2000 and a computer attached to a LAN, (which doesn't use registry settings), that programatically determines if the computer is connected to a DUN entry. I have tried the following function but it returns true, even if the machine hasn't connected to the DUN entry :

function DUNConnected : Boolean;
var BufSize, NumEntries : Longint;
    Entries             : TRasConn;
    Stat                : TRasConnStatus;
begin
  Result := False;
  Entries.dwSize := SizeOf(TRasConn);
  BufSize := SizeOf(TRasConn) * 100;
  FillChar(Stat, Sizeof(TRasConnStatus), 0);
  Stat.dwSize := Sizeof(TRasConnStatus);
  if RasEnumConnections(@Entries, BufSize, NumEntries) = 0 then
    if RasGetConnectStatus(Entries.hrasconn, Stat) = 0 then
      Result := True
    else
      Result := False
  else
    ShowMessage('RasEnumConnections failed');

Can you either tell me how to ammend this function or let me know of a better way of achieving this.
0
Comment
Question by:Developer_Dan
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
raidos earned 50 total points
ID: 6230833
The Result of RasGetConnectStatus doesn't say anyting but if the function succeded or failed, you need to Read the connection status from Your stat variable

If Stat.RasConnState = RASCS_Connected Then
  Result := TRUE
Else
  Result := FALSE;

Also you might want to make sure that NumEntries is larger than 0 before trying this.

Good luck.

//raidos


0
 
LVL 3

Expert Comment

by:raidos
ID: 6230844
By the way, The TRASCONN Structure differs on all Operating systems...

You need to dynamically check what OS is running and decide what structure to use...


//raidos
0
 

Author Comment

by:Developer_Dan
ID: 6230893
Cheers Raidos, you're the best !!
0
 
LVL 2

Expert Comment

by:FrodoBeggins
ID: 6230902
Hey, man, if you want to see if you are connected why don't you jst ping any server like http://www.yahoo.com/ or http://www.microsoft.com/ ? If THEY go offline, then the net is over :)
Pinging is regular way for me to check if there is connection. It is not 100% solution, byt for my programs it's alwais suitable. Don't forget to set big enough timeout.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question