如何在启动机器时自动运行adsl拨号(1)[8]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zhujunfeng 的 blog

        end;
    end;
    result := 0;
end;

function checkconn(fentryname:string):boolean;
begin
    hrasconn := getactiveconnhandle(fentryname);
    if hrasconn <> 0 then
      result:=true
    else
      result:=false;
end;

procedure rasdialfunc(unmsg : dword;frasconnstate : trasconnstate;fdwerror : dword); stdcall;
var
  buf: array [0..255] of char;
begin
  try
    logmessage(rasconnectionstatetostring(frasconnstate));
    if frasconnstate = rascs_connected then begin
        afterconnect;
    end
    else if frasconnstate = rascs_disconnected then begin
        rasgeterrorstringa(fdwerror, @buf[0], sizeof(buf));
        logmessage(buf);
        disconnected;
    end;
  except
  end;

end;

procedure dial(fentryname, fusername, fpassword : string);
var
    rdparams : trasdialparams;
    dwret    : dword;
    buf      : array [0..255] of char;
begin
  try
    hrasconn := getactiveconnhandle(fentryname);
    if hrasconn <> 0 then begin
        logmessage('connection already active');
        exit;
    end;

    // setup ras dial parameters
    fillchar(rdparams, sizeof(rdparams), 0);
    rdparams.dwsize              := sizeof(trasdialparams);
    strcopy(rdparams.szusername,  pchar(fusername));
    strcopy(rdparams.szpassword,  pchar(fpassword));
    strcopy(rdparams.szentryname, pchar(fentryname));
    rdparams.szphonenumber[0]    := #0;
    rdparams.szcallbacknumber[0] := '*';
    rdparams.szdomain            := '*';

    hrasconn := 0;;
    dwret  := rasdiala(nil, nil, @rdparams, 0, @rasdialfunc, @hrasconn);
    if dwret <> 0 then
    begin
        rasgeterrorstringa(dwret, @buf[0], sizeof(buf));
        logmessage(inttostr(dwret) + ' ' + buf);
        disconnected;
    end
    else
    begin
        logmessage('dialing ''' + fentryname + '''');
    end;
  except
  end;
end;

begin
  try
    dirpath:=extractfilepath(paramstr(0));
    f:=tinifile.create(dirpath+'conf.ini');
    entryname:=f.readstring('rasdial','entryname','');
    username:=f.readstring('rasdial','username','');
    password:=f.readstring('rasdial','password','');
    checkvisit:=f.readbool('rasdial','visit',false);
    visithost:=f.readstring('rasdial','host','');
    visiturl:=f.readstring('rasdial','url','');
    visitparam:=f.readstring('rasdial','param','');
    f.free;

    if not checkconn(entryname) then
    begin

        dial(entryname,username,password);

    end
    else
    begin
      logmessage('----------'+getip+'----------');
      isconnected:=true;
    end;
    while not isconnected do
      sleep(1000);
  except
  end;   
end.

然后编译后产生一个console application,
编写自己的conf.ini,填入自己的连接名称,用户名,密码等参数

本文关键:adsl 拨号 服务
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top