Показать сообщение отдельно
  #2  
Старый 29.01.2016, 12:47
Аватар для Aristarh Dark
Aristarh Dark Aristarh Dark вне форума
Модератор
 
Регистрация: 07.10.2005
Адрес: Москва
Сообщения: 2,907
Версия Delphi: Delphi XE
Репутация: выкл
По умолчанию

Как-то так:
Код:
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.
__________________
Некоторые программисты настолько ленивы, что сразу пишут рабочий код.

Если вас наказали ни за что - радуйтесь: вы ни в чем не виноваты.
Ответить с цитированием