Solved

Programatically testing if a computer is connected to a DUN connection

Posted on 2001-06-27
4
138 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now