반응형

uses 
shellapi; 

{...} 

Procedure ShellExecute_AndWait(FileName:String;Params:String); 
var 
exInfo : TShellExecuteInfo; 
Ph : DWORD; 
begin 
FillChar( exInfo, Sizeof(exInfo), 0 ); 
with exInfo do 
begin 
cbSize:= Sizeof( exInfo ); 
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT; 
Wnd := GetActiveWindow(); 
ExInfo.lpVerb := 'open'; 
ExInfo.lpParameters := PChar(Params); 
lpFile:= PChar(FileName); 
nShow := SW_SHOWNORMAL; 
end; 
if ShellExecuteEx(@exInfo) then 
begin 
Ph := exInfo.HProcess; 
end 
else 
begin 
ShowMessage(SysErrorMessage(GetLastError)); 
exit; 
end; 
while WaitForSingleObject(ExInfo.hProcess, 50) <> WAIT_OBJECT_0 do 
Application.ProcessMessages; 
CloseHandle(Ph); 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
ShellExecute_AndWait('FileName','Parameter'); 
end; 

반응형
반응형