Remote control: Dial-up Internet in Delphi program

Source: Internet
Author: User

The use of modem dial-up Internet is still the most personal Internet users choose the way. If you can start a dial-up connection in our application (such as the auto-dialing feature in the IE browser program), it will undoubtedly be convenient for our software users (no need to switch applications, running dial-up networks), improve the friendliness of our software and improve the competitiveness of the software.
Under Win9x, if Dial-Up Networking is installed, there will be two dial-up network management libraries RasApi32.DLL and RasApi16.DLL under the system directory of the Windows system, and we can use the functions to create and modify dial-up connections. Dial-up connections are made using the specified dial-up connection.

A. New dial-up connection
When a dial-up connection is already established in the Win9x system, the existing dial-up connection can be leveraged. If you do not have a dial-up connection, you need to create a new dial-up connection. The corresponding function is provided in Rasapi, whose function is named Rascreatephonebookentrya and the function prototype is:
function Rascreatephonebookentrya (Hwnd:thandle;lpszphonebook:pchar): DWORD;
stdcall; {in interface section}
function Rascreatephonebookentrya; External ' Rasapi32.dll '; {In implementation section}
Parameters:
HWND (THANDLE): A handle to the parent window of a new dial-up connection window, which can be a tform handle, a nil table; Windows desktop
Lpszphonebook (Pchar): Phone book name, no effect under Win9x, can be set to an empty string
function return value:
0 indicates successful execution; otherwise, it is an error.

Here is an example of a new dial-up connection.
{New dial-up connection}
procedure Tform1.button1click (sender:tobject);
var
   Dwresult:dword;
Begin
    //Create a new dial-up connection in the current window
     dwresult: = Rascreatephonebookentrya ( Handle, ");
     If dwresult = 0 Then
        memo1.lines.add (' New dial-up connection succeeded! ')
     Else
        memo1.lines.add (' New dial-up connection failed! ')
End;

Second, modify the properties of the specified dial-up connection
If the user needs to modify the properties of a dial-up connection such as phone number, country and area code, connection method, server type, etc., it can be implemented with the RASAPI function, whose function name is Raseditphonebookentrya and the function prototype is:
function Raseditphonebookentrya (hwnd:thandle; lpszphonebook:pchar;
Lpszentryname:pchar): Dword;stdcall; {in interface section}
function Raseditphonebookentrya; External ' Rasapi32.dll '; {In implementation section}
Parameters:
HWND (THANDLE): A handle to the parent window of a new dial-up connection window, which can be a handle for tform and a nil representation
Windows Desktops (Desktop)
Lpszphonebook (Pchar): Phone book name, no effect under Win9x, can be set to an empty string
Lpszentryname: (pchar): The name of the dial-up connection to be modified, such as ' 163 ', ' 169 ', etc.
function return value:
0 indicates successful execution; otherwise, it is an error.

The following is an example that modifies the properties of a specified dial-up connection.
{Modify specified dial-up connection properties}
Procedure Tform1.button2click (Sender:tobject);
Var
Dwresult:dword;
strdialname:string;
Begin
Strdialname: = ' 163 ';//The name of the dial-up connection is set to 163
Specify the properties of the Modify dial-up connection in the current window
Dwresult: = Raseditphonebookentrya (Handle, ", PChar (Strdialname));
If dwresult = 0 Then
Memo1.lines.add (' Modify dial-up connection ' + Strdialname + ' success! ')
Else
Memo1.lines.add (' Modify dial-up connection ' + Strdialname + ' failed! ')
End
Third, get the dial-up connection name that is available on the current system
In order for the user to choose to use a dial-up connection for dialing, we need to get the name of the dial-up connection that was established on the system. After a dial-up connection is established, Win9x writes the name and attributes of the dial-up connection in the registry, and we can obtain the dial-up connection name that is available on the current system and the default connection name that is set in Internet Explorer from the registry.
The HKEY_USERS in the registry. defaultremoteaccessaddresses, lists the name of the dial-up connection that has been established in the Dial-up network and its property settings, where the name of the object is the name of the available dial-up connection, and the value for each dial-up connection is the property setting. We just have to read the name of each item to get the dial-up connection name available on the current system.
If the default connection name is set in Internet Explorer (view = "internet option =" Connection = "Connection =" setting = "Use the following Dial-Up Networking connection), then the registry is HKEY_USERS. Defaultremoteaccess, there is a string type key value, the key value name Internetprofile, whose value is the default connection name set in Internet Explorer.

The following is an example of getting the name of a dial-up connection available on the current system.
{Note Adding registry cells in uses for operation of the Registry}
{Gets the dial-up connection name that is available on the current system}
Procedure Tform1.button3click (Sender:tobject);
Var
Registrytemp:tregistry;
Stringstemp:tstringlist;
Intindex:integer;
Begin
Registrytemp: = tregistry.create;
Stringstemp: = tstringlist.create;
With Registrytemp do
Begin
Rootkey: = hkey_users;//root Key set to HKEY_USERS
If a child key exists. Defaultremoteaccessaddresses
If Openkey ('. Defaultremoteaccessaddresses ', false) then
GetValueNames (stringstemp);//read out the name of each item, that is, the dial-up connection name
Closekey;
End
Dial-up connections available in the current system
Memo1.lines.add (' ****************** current system has ' + INTTOSTR (stringstemp.count)
+ ' available dial-up Connections as follows **************** ');
For intindex: = 0 to Stringstemp.count-1 do
Memo1.lines.add (stringstemp.strings[Intindex]);

Lists the default connection names set in Internet Explorer
If Registrytemp.openkey ('. Defaultremoteaccess ', false) then
Memo1.lines.add (the default connection name set in Internet Explorer is ' +
Registrytemp.readstring (' internetprofile '));

Freeing memory
Registrytemp.free;
Stringstemp.free;
End

Iv. dialing with the specified dial-up connection
The purpose of the above three jobs is to dial up the internet, now take a look if dial-up connection with the specified dial-up connections. The best way to do this is to call Win9x's Dial-Up Networking service, which is the off-the-shelf program running Win9x.
In the Delphi program can use the following code to implement dial-up Internet:
WinExec (' rundll32.exe rnaui.dll,rnadial 163 ', SW_SHOWNORMAL);
Where the last parameter in the string "163" is the name of the dial-up connection.

The following is an example of Dial-Up networking with a specified dial-up connection.
{Dial-up with the specified dial-up connection}
Procedure Tform1.button4click (Sender:tobject);
Var
strdialname:string;
Begin
Strdialname: = ' 163 ';//The name of the dial-up connection is set to 163
Memo1.lines.add (' ****************** Dial-up connection ' + Strdialname
+ ' Implement dial-up Internet **************** ');
WinExec (PChar (' rundll32.exe rnaui.dll,rnadial ' + strdialname), SW_SHOWNORMAL);
End

The above program is debugged under pwin98+delphi3.0.

Remote control: Dial-up Internet in Delphi program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.