function WinExecAndWait(Path: PChar; Visibility: Word): Word;varInstanceID: THandle;Msg: TMsg;beginInstanceID := WinExec(Path, Visibility);if InstanceID < 32 then { значение меньшее чем 32 указывает на ошибку запуска }WinExecAndWait := InstanceIDelserepeatwhile PeekMessage(Msg, 0, 0, 0, pm_Remove) dobeginif Msg.Message = wm_Quit then Halt(Msg.WParam);TranslateMessage(Msg);DispatchMessage(Msg);end;until GetModuleUsage(InstanceID) = 0;WinExecAndWait := 0;end; |