if CreateProcess(nil, PChar(TNXStrings.Format(FileName, Params)), @SecAttributes, @SecAttributes, True, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, Process) then
try
{ loop while running }
repeat
{ update running flag }
Running := WaitForSingleObject(Process.hProcess, 100);
{ loop while data available }
repeat
{ read output block... }
Read := 0;
ReadFile(ReadHandle, Buffer[0], BufSize, Read, nil);
Buffer[Read] := #0;
{ ...and convert it to
ansi }
OemToAnsi(Buffer, Buffer);
{ callback assigned? }
if Assigned(Callback) then
Callback(string(Buffer));
until (Read < BufSize);
{ process messages }
Application.ProcessMessages;
until (Running <> WAIT_TIMEOUT);
{ set result }
Result := True;
finally
{ close handles }
CloseHandle(Process.hProcess);
CloseHandle(Process.hThread);
end;