Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programatically testing if a computer is connected to a DUN connection

Posted on 2001-06-27
4
Medium Priority
?
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
raidos earned 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

719 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