Solved

Programatically testing if a computer is connected to a DUN connection

Posted on 2001-06-27
4
146 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Title # Comments Views Activity
Delphi 2 68
Delphi Yen format 3 45
Firemonkey android show image from resource ? 1 46
How do I add a client SSL certificate to a SOAP client in Rad Studio Delphi? 2 103
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

765 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