procedure RunAndWaitShell(Executable,parameters:stri ng ;Visibility:integer);
var
Info:TShellExecuteInfo;
pInfo:PShellExecuteInfo;
exitCode:DWord;
begin
{Pointer to Info}
pInfo:=@Info;
{Fill info}
with Info do
begin
cbSize:=SizeOf(Info);
fMask:=SEE_MASK_NOCLOSEPROCESS;
wnd:=application.Handle;
lpVerb:=nil;
lpFile:=PChar(Executable);
{Executable parameters}
lpParameters:=Pchar(parameters+#0);
lpDirectory:=nil;
nShow:=Visibility;
hInstApp:=0;
end;
{Execute}
ShellExecuteEx(pInfo);
{Wait to finish}
repeat
exitCode := WaitForSingleObject(Info.hProcess,500);
Application.ProcessMessages;
until (exitCode <> WAIT_TIMEOUT);
end;
سپس در برنامه این را مینویسی:
RunAndWaitShell(
My Program Path,
'My Parameters,Sw_ShowNormal);