http://thecoadletter.com/homepages/dsp/ftp/d30free/dialup.zip
function Tmanage_setup.dial(dial_name:string):boolean;//进行拨号尝试
var filename:string;
filehandle:textfile;
filestring:ansistring;
tempchar:char;
begin
filename:='c:/rasdial.log';
favcon_in.runcommand('cmd','/c rasdial.exe "'+dial_name+'" '+dial_username.text+' '+dial_password.text+' >'+'"'+filename+'"');
//分析rasdial.log文件
assignfile(filehandle,filename);
reset(filehandle);
while not eof(filehandle) do
begin
read(filehandle,tempchar);
filestring:=filestring+tempchar;
end;
closefile(filehandle);
if strpos(pchar(filestring),'命令已完成')<>nil then//拨号成功
dial:=true
else
dial:=false;
end;
procedure Tmanage_setup.close_dial(dial_name:string);//关闭拨号连接
begin
try
Favcon_in.runcommand('cmd','/c rasdial.exe "'+dial_name+'" /DISCONNECT');
except
end;
end;
procedure TFavcon_in.runcommand(filename,para:ansistring);
var WindowHandle:HWND;
var commandline:ansistring;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
commandline:=filename+' '+para;
//showmessage(commandline);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_HIDE ;
if not CreateProcess(nil,
pchar(commandline),
nil,
nil,
false,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo) then
begin
end
else
begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
//命令执行完后再会继续下去
end;
end;