Как-то так:
Код:
procedure RunAndWait(AFileName:string; ATimeout:Cardinal);
var
Time:Cardinal;
shExecInfo:PShellExecuteInfo;
begin
New(shExecInfo);
shExecInfo^.cbSize := SizeOf(SHELLEXECUTEINFO);
shExecInfo^.fMask := SEE_MASK_NOCLOSEPROCESS;
shExecInfo^.Wnd := 0;
shExecInfo^.lpVerb := 'runas';
shExecInfo^.lpFile := PChar(ExtractFileName(AFileName));
shExecInfo^.lpParameters := ' /install';
shExecInfo^.lpDirectory := PChar(ExtractFilePath(AFileName));
shExecInfo^.nShow := SW_HIDE;
shExecInfo^.hInstApp := 0;
ShellExecuteEx(shExecInfo);
Time:=GetTickCount;
// WaitForInputIdle(shExecInfo^.hProcess, INFINITE);
WaitForSingleObject(shExecInfo^.hProcess,ATimeout);
Time:=GetTickCount-Time;
// ShowMessage('Time '+IntToStr(Time));
Dispose(shExecInfo);
end;
Я так Flash ActiveX адобовский ставлю, но в целом думаю понятно что нужно будет переделать.
А про то что hProcess не всегда заполняется - там же написано, что при определенных масках. А мы всех обманем и заюзаем:
Цитата:
SEE_MASK_NOCLOSEPROCESS (0x00000040)
Use to indicate that the hProcess member receives the process handle. This handle is typically used to allow an application to find out when a process created with ShellExecuteEx terminates. In some cases, such as when execution is satisfied through a DDE conversation, no handle will be returned. The calling application is responsible for closing the handle when it is no longer needed.
|