NT如何简单编程,定时拨号,然后断开?(100分)

  • 主题发起人 主题发起人 goldenforest
  • 开始时间 开始时间
G

goldenforest

Unregistered / Unconfirmed
GUEST, unregistred user!
要在n台NT服务器间实现SQL的复制功能,但没有没有实时连接,我设计利用SQL7.0的复制(可以使用任务定时完成),这样就要求系统能够自动调用NT的
拨号系统,定时(或者调用)拨号.
我看了以前提的问题,仍不明白,找了一些控件,都是for win95,没有找到
for NT的,都说RAS,怎么用,请哪位朋友帮忙解释一下,万分感谢!
 
你仿照别人附的源程序不就学会了吗?
有的很简单的,只要设几个属性就可以的!
简单的几个方法!
 
unit powerdial;

interface

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



type
rasDialExtensions = record
dwSize,dwfOptions,hwndParent,reserved: integer;
end;

lpRasDialExtensions = ^rasDialExtensions;
rasDialParams = record
dw_size: Cardinal;
szEntryName:Array [0..256] of char;//string;
szPhoneNumber:Array [0..128] of char;//string;
szCallBackNumber:Array [0..128] of char;// string;
szUserName:Array [0..256] of char;//string;
szPassword:Array [0..256] of char;//string;
szDomain:Array [0..15] of char;// string;
end;
lprasDialParams = ^rasDialParams;

LPRASCONNSTATUS =^RASCONNSTATUS ;
RASCONNSTATUS = record
dw_size : Cardinal;
rasconnstate : integer;
dw_Error : Cardinal;
szDeviceType : Array [0..32] of char;
szDeviceName : Array [0..16] of char;
end;

function RasDialW(lpoRasDialExtensions: lprasDialExtensions;
lpszPhonebook: pChar; lpoRasDialParams: lprasDialParams;
dwNotifierType: integer; lpvNotifier: integer;
var lphRasConn: cardinal): integer;stdcall;external 'rasapi32.dll';
function RasDialA(lpoRasDialExtensions: lprasDialExtensions;
lpszPhonebook: pChar; lpoRasDialParams: lprasDialParams;
dwNotifierType: Cardinal; lpvNotifier: Cardinal;
var lphRasConn: cardinal): integer;stdcall;external 'rasapi32.dll';
Function RasHangUpW(lphRasConn : Cardinal): integer;stdcall;external 'rasapi32.dll';
function RasGetConnectStatusA(hrasconn:cardinal;
var rasconnstatus:RASCONNSTATUS): integer;stdcall;external 'rasapi32.dll';
function RasGetErrorStringW(errcode :integer;
Var errstring:Pchar;
errlong:integer):integer;stdcall;external 'rasapi32.dll';

function ShowStatusString(param: Cardinal): string;
function rasdialconnect(DialEntry:string;
UserName:string;
UserPass:string;
Var dialhandle:Cardinal;
Var Dialerrorcode : integer): boolean;
Function powerhangup(DialHandle : Cardinal;
Var Dialerrorcode : integer):Boolean;


implementation



function ShowStatusString(param: Cardinal): string;
var
ls_Message: string;
begin
case param of
0:
ls_Message := '打开端口';//'Open Port';
1:
ls_Message := '端口已打开';//'Port Opened';
2:
ls_Message := '连接设备';//'Connect Device';
3:
ls_Message := '设备已连接';//'Device Connected';
4:
ls_Message := '所有设备已连接';//'All Devices Connected';
5:
ls_Message := '验证身份';//'Authenticate';
6:
ls_Message := '身份验证';//'Auth. Notify';
7:
ls_Message := '重新验证身份';//'Auth. Retry' ;
8:
ls_Message := '验证身份响应';//'Auth. Callback';
9:
ls_Message := '修改口令';//'Auth. Change Password';
10:
ls_Message := '注册网络';//'Auth. Project';
11:
ls_Message := '认证连接速度';//'Auth. Link Speed';
12:
ls_Message := 'Auth. Ack';
13:
ls_Message := '重新认证';//'ReAuthenticate';
14:
ls_Message := '身份已验证';//'Authenticated';
15:
ls_Message := 'Prepare For Callback';
16:
ls_Message := '等待调制解调器复位';//'Wait For Modem Reset';
17:
ls_Message := '等待响应';//'Wait For Callback';
8192:
ls_Message := '连接成功';//'Connected!';
end;

ShowStatusString := ls_Message;
end;

function rasdialconnect(DialEntry:string;
UserName:string;
UserPass:string;
Var dialhandle:Cardinal;
Var Dialerrorcode : integer): boolean;
var
Pdialparams: rasDialParams;
Pdialstatus : RASCONNSTATUS;
cc: cardinal;
s_ok: integer;

begin
Dialerrorcode := 0;
Pdialparams.dw_size := 1052;
Strcopy( Pdialparams.szEntryName ,Pchar( DialEntry));//PChar('ChinaNet');
Pdialparams.szPhoneNumber := '';//PChar('163');
Pdialparams.szCallBackNumber := '';//PChar('4892803');
strcopy( Pdialparams.szUserName ,Pchar(UserName));//PChar('jschem1');
strcopy( Pdialparams.szPassword ,Pchar(UserPass));//PChar('7365');
Pdialparams.szDomain := '';
DialHandle := 0;
cc := 2147483647;
Pdialstatus.dw_size := sizeof(RASCONNSTATUS);
DialErrorCode := RasDialA(nil,nil,@Pdialparams,cc,0,DialHandle);
if DialErrorCode = 0 Then
begin
Pdialstatus.dw_size := sizeof(RASCONNSTATUS);
s_ok := RasGetConnectStatusA(DialHandle,Pdialstatus);
while (Pdialstatus.dw_Error = 0 )and (Pdialstatus.RasConnstate <> 8192)
and (s_ok <> 6) do
begin
s_ok := RasGetConnectStatusA(dialhandle,Pdialstatus);
// Es.Text := ShowStatusString(temps.RasConnstate);
Application.ProcessMessages;
end;
If Pdialstatus.RasConnstate = 8192 Then
begin
rasdialconnect := True;
exit;
end;
end;
//Es.text := '连接失败!';
rasdialconnect := False;
end;

Function powerhangup(DialHandle : Cardinal;
Var Dialerrorcode : integer):Boolean;
var
s_ok : integer;
Pdialstatus : RASCONNSTATUS;
begin
DialErrorCode := 0;
DialErrorCode := RasHangUpW(DialHandle);
sleep(3000);
{ RasHangUp, to call RasGetConnectStatus(hrasconn) and Sleep(0)
in a loop until RasGetConnectStatus returns ERROR_INVALID_HANDLE.
}
Pdialstatus.dw_size := sizeof(RASCONNSTATUS);
s_ok := RasGetConnectStatusA(DialHandle,Pdialstatus);
while (Pdialstatus.dw_Error = 0 )and (s_ok =0) do
begin
s_ok := RasGetConnectStatusA(DialHandle,Pdialstatus);
Application.ProcessMessages ;
end;
if DialErrorCode <>0 Then
begin
powerhangup := False;
exit;
end;
if Pdialstatus.dw_Error <> 0 Then
begin
powerhangup := False;
exit;
end;
powerhangup := True;
end;



end.
 
接受答案了.
 

Similar threads

后退
顶部