1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| function ExecuteWaitFile( ExeFile, Parameters: string): Boolean;
procedure WaitFor(processHandle: THandle);
var
AMessage : TMsg;
Result : DWORD;
begin
repeat
Result := MsgWaitForMultipleObjects(1,
processHandle,
False,
INFINITE,
QS_PAINT or
QS_SENDMESSAGE);
if Result = WAIT_FAILED then
Exit;
if Result = ( WAIT_OBJECT_0 + 1 ) then
begin
while PeekMessage(AMessage, 0, WM_PAINT, WM_PAINT, PM_REMOVE) do
DispatchMessage(AMessage);
end;
until result = WAIT_OBJECT_0;
end;
var
ExecuteCommand: array[0 .. 512] of Char;
StartUpInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
begin
StrPCopy(ExecuteCommand , ExeFile + ' ' + Parameters);
FillChar(StartUpInfo, SizeOf(StartUpInfo), #0);
StartUpInfo.cb := SizeOf(StartUpInfo);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow := SW_MINIMIZE;
if CreateProcess(nil,
ExecuteCommand,
nil,
nil,
False,
CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
nil,
PChar(ExtractFileDir(ExeFile)),
StartUpInfo,
ProcessInfo) then
begin
WaitFor(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
result := true;
end
else
result := false;
end; |
Partager