Automatic modem dialing using Delphi

Source: Internet
Author: User

If you can start dialing in our application
Connections (such as the automatic dialing function in IE browser programs) will undoubtedly make it easier for our software users (no longer need to switch applications,
To improve the friendliness of our software and improve the competitiveness of the software.
If a dial-up network is installed in Win9x, two dial-up networks are managed under the system directory of windows.
Library rasapi32.dll and rasapi16.dll. We can use the functions to create and modify dial-up connections, and use the specified
Dial-up connection.
 
1. Create a dial-up connection
When a dial-up connection has been established in the Win9x system, a ready-made dial-up connection can be used. If no dial-up connection exists, you need to create a new one.
A dial-up connection. Rasapi provides a function named rascreatephonebookentrya. The function is prototype:
Function rascreatephonebookentrya (hwnd: thandle; lpszphonebook: pchar): DWORD;
Stdcall; {In interface}
Function rascreatephonebookentrya; External 'rasapi32. dll '; {in Implementation}
Parameters:
Hwnd (thandle): the handle of the parent window of the new dial-up connection window. It can be the handle of tform, which is represented by nil.
Windows Desktop)
Lpszphonebook (pchar): the name of the phone book. It does not work in Win9x and can be set as a null string.
Function return value:
0 indicates that the execution is successful; otherwise, it indicates an error.
 
The following is an example of creating a dial-up connection.
{New dial-up connection}
Procedure tform1.button1click (Sender: tobject );
VaR
Dwresult: DWORD;
Begin
// Create a dial-up connection in the current window
Dwresult: = rascreatephonebookentrya (handle ,'');
If dwresult = 0 then
Memo1.lines. Add ('new dial-up connection successful! ')
Else
Memo1.lines. Add ('new dial-up connection failed! ')
End;
 
2. Modify the attributes of a specified dial-up connection
If you need to modify the dialing connection attributes, such as the phone number, country and district number, connection method, and server type
And can be implemented using the rasapi function. Its name is raseditphonebookentrya, and its prototype is:
Function raseditphonebookentrya (hwnd: thandle; lpszphonebook: pchar;
Lpszentryname: pchar): DWORD; stdcall; {In interface}
Function raseditphonebookentrya; External 'rasapi32. dll '; {in Implementation}
Parameters:
Hwnd (thandle): the handle of the parent window of the new dial-up connection window. It can be the handle of tform, which is represented by nil.
Windows Desktop)
Lpszphonebook (pchar): the name of the phone book. It does not work in Win9x and can be set as a null string.
Lpszentryname :( pchar): name of the dial-up connection to be modified, such as '123456' and '1234568 '.
Function return value:
0 indicates that the execution is successful; otherwise, it indicates an error.
 
The following is an example of modifying the attributes of a specified dial-up connection.
{Modifying the attributes of a specified dial-up connection}
Procedure tform1.button2click (Sender: tobject );
VaR
Dwresult: DWORD;
Strdialname: string;
Begin
Strdialname: = '000000'; // set the name of the dial-up connection to 163.
// Modify the attributes of the dial-up connection in the current window
Dwresult: = raseditphonebookentrya (handle, '', pchar (strdialname ));
If dwresult = 0 then
Memo1.lines. Add ('modify dial-up connection' + strdialname + 'successfully! ')
Else
Memo1.lines. Add ('modify dial-up connection' + strdialname + 'failed! ')
End;
 
3. Obtain the name of available dial-up connections in the current system
To allow users to select a dial-up connection for dialing, we need to obtain the name of the dial-up connection established in the system. After
After the dial-up connection, Win9x writes the name and attribute of the dial-up connection in the registry. We can obtain
The name of the dial-up connection and the default connection name set in Internet Explorer.
In the Registry's HKEY_USERS/. Default/RemoteAccess/addresses, list
The name of the dial-up connection and its attribute settings. The name of each project is the name of the available dial-up connection, and the value of each item is the name of each dial-up connection.
Connection property settings. You only need to read the name of each target to obtain the name of the dial-up connection available in the current system.
If the default connection name is set in Internet Explorer (view = Internet Options = connection =)
Set = to use the following dial-up network connection), there is a character in the Registry's HKEY_USERS/. Default/RemoteAccess
Key Value of the string type. The key value is internetprofile, and the value is the default connection name set in Internet Explorer.
 
The following is an example of obtaining the name of a dial-up connection available in the current system.
{Note: Add a Registry Unit to uses to operate the Registry}
{Obtain the name of the dial-up connection available in 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; // set the root key to HKEY_USERS.
// If the sub-key. Default/RemoteAccess/addresses exists
If openkey ('. Default/RemoteAccess/SES SSEs', false) then
Getvaluenames (stringstemp); // read the name of each project, that is, the name of the dial-up connection.
Closekey;
End;
// Available dial-up connections in the current system
Memo1.lines. Add ('********************' + inttostr (stringstemp. Count) in the current system)
+ 'Available dial-up connections are as follows ****************');
For intindex: = 0 to stringstemp. Count-1 do
Memo1.lines. Add (stringstemp. Strings [intindex]);
 
// List the default connection names set in Internet Explorer
If registrytemp. openkey ('. Default/remoteaccess', false) then
Memo1.lines. Add ('default connection name set in Internet Explorer '+
Registrytemp. readstring ('internetprofile '));
 
// Release the memory
Registrytemp. Free;
Stringstemp. Free;
End;
 
4. Use the specified dial-up connection for dialing
The purpose of the above three tasks is to dial up the Internet. Now let's take a look at how to use the specified dial-up connection to dial the internet.
The best way is to call Win9x's dial-up network service and run the ready-made Program Under Win9x.
In the Delphi program, you can use the following code to implement dial-up Internet access:
Winexec('rundll32.exe rnaui. dll, rnadial 163 ', sw_shownormal );
The last parameter "163" in the string is the name of the dial-up connection.
 
The following is an example of using a specified dial-up connection for dial-up access.
{Use the specified dial-up to connect to the dial-up Internet}
Procedure tform1.button4click (Sender: tobject );
VaR
Strdialname: string;
Begin
Strdialname: = '000000'; // set the name of the dial-up connection to 163.
Memo1.lines. Add ('******************** use dial-up connection' + strdialname
+ 'Achieve dial-up Internet access ****************');
Winexec (pchar('rundll32.exe Rui. dll, rnadial '+ strdialname), sw_shownormal );

 

========================================================== ======================================

After dialing, the new IP address is obtained. What do you want to do? Haha... Free to use

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.