Solved

Programatically testing if a computer is connected to a DUN connection

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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