必須使用 ShellAPI
代碼: 選擇全部
procedure Tform1.Button2Click(Sender: TObject);
var
hw: HWND;
execinfo : TShellExecuteInfo;
begin
FillChar(execinfo,SizeOf(execinfo),0);
execinfo.cbSize:=sizeof(execinfo);
execinfo.lpVerb:='open';
execinfo.lpfile:=Pchar('ping.exe'); //所要執行的外部
execinfo.lpParameters:=Pchar('www.hinet.net'); //參數
execinfo.fMask:=SEE_MASK_NOCLOSEPROCESS;
execinfo.nShow:=SW_HIDE;
if (not ShellExecuteEx(@execinfo)) then
begin
ShowMessage('無法執行');
exit;
end;
Application.Minimize;
WaitForSingleObject(execinfo.hProcess,INFINITE); //會一直等待直到執
// 行的外部程式結束,才會把控制權交給你的應用程式。
Application.Restore;
end;