Solved

Detect Internet DialUp connections

Posted on 1998-11-27
8
172 Views
Last Modified: 2010-04-04
Hi All,

I want to write a little application to detect internet dialup connections and launchs my application (like ICQ NetDetect). How can I do that?

Thanks in advance.
0
Comment
Question by:sergio_2001
  • 4
  • 2
  • 2
8 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 1348263
sergio_2001,

you can use something like below to check 'remote connection' key it changes when a ras connection is made.
to see what i mean run regedit and check HKEY_LOCAL_MACHINE\
System\CurrentControlSet\Services\RemoteAccess\remote connection  value then close regedit and connect to net
and reopen regedit and recheck you'll see value has changed.

Function GetRasStatus:Longint;   { get number of RAS onnections }var
MyRegistry:TRegistry;
begin         { Change registry to load every time }
MyRegistry:=TRegistry.Create;
With MyRegistry dobegin
RootKey:=HKEY_LOCAL_MACHINE;
OpenKey('System\CurrentControlSet\Services\RemoteAccess',True);
ReadBinaryData('Remote Connection',Result,SizeOf(Result));
CloseKey;
end;
MyRegistry.Free;
end;
Function DetectConnection:Boolean;
var
IPList:TStrings;
begin
IPList:=LocalIPList;
Result:=IPList.Count<>0;
If GetRasStatus>0 then Result:=True;
end;

Barry,
0
 

Author Comment

by:sergio_2001
ID: 1348264
inthe,

Your  answer looks good. But I have some problems with the function:

Function DetectConnection:Boolean;
    var
    IPList:TStrings;
    begin
    IPList:=LocalIPList; {where is declared? or what I must include here?}
    Result:=IPList.Count<>0;
    If GetRasStatus>0 then Result:=True;
end;

The IPList:=LocalIPList; ?????

Waiting for comments...
thanks
0
 
LVL 17

Expert Comment

by:inthe
ID: 1348265
hi,
i'll post a full unit tonight gmt time
you dont have to use some of the lines just getting status of key in registry will do
Regards Barry

0
 
LVL 17

Expert Comment

by:inthe
ID: 1348266
Hi Sergio
1 button on form with a onclick event

unit Unit1;

interface

uses
  Windows, Messages,Registry, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
   
  public
   
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
Function GetRasStatus:Longint;
var
MyRegistry:TRegistry;
begin
MyRegistry:=TRegistry.Create;
With MyRegistry do begin
RootKey:=HKEY_LOCAL_MACHINE;
OpenKey('System\CurrentControlSet\Services\RemoteAccess',True);
ReadBinaryData('Remote Connection',Result,SizeOf(Result));
CloseKey;
end;
MyRegistry.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=inttostr(getrasstatus);
end;

end.
 Regards Barry
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:inthe
ID: 1348267
sorry dude wrong one here is correct one:
unit Unit1;

interface

uses
  Windows, Messages,Registry,shellapi, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
    end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
Function GetRasStatus:Longint;
var
MyRegistry:TRegistry;
begin
MyRegistry:=TRegistry.Create;
With MyRegistry do begin
RootKey:=HKEY_LOCAL_MACHINE;
OpenKey('System\CurrentControlSet\Services\RemoteAccess',True);
ReadBinaryData('Remote Connection',Result,SizeOf(Result));
CloseKey;
end;
MyRegistry.Free;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
if  getrasstatus = 1
then
ShellExecute(Handle, NIL, 'c:\windows\calc.exe', NIL, NIL, sw_ShowNormal)
else showmessage('not connected');
end;

end.
 
0
 

Author Comment

by:sergio_2001
ID: 1348268
Hi inthe,

I will evaluate your answer to grade you ASAP.

regards
0
 

Expert Comment

by:Mikkel_48
ID: 22583005
I have a very similar requirement to the original question. In my case I wish to keep a log of times and dates I am connected to the internet via my Dial-Up Connection The solution should work on Windows 2000 upwards to Vista and be compatible with Delphi.
I looked at the provided solution but in my Windows (XP, SP3) if I look at the registry key specified 'System\CurrentControlSet\Services\RemoteAccess', there is no binary data value ''Remote Connection'. Am I missing something or was that correct for Windows 98, but later versions don't have it?
Any comments from the solution provider (or the question poster)? I am happy to pose a new question if necessary.
0
 

Expert Comment

by:Mikkel_48
ID: 22583519
Addendum to my previous comment:
I would still like the solution providers comments on his solution and curent Windows compatibility but some searching has revealed many questions and solutions on this topic and it will take me some time to research and test them all. Therefore not going to post a new question yet.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

12 Experts available now in Live!

Get 1:1 Help Now