bu procedure ile islem bitene kadar programın bekler
bu tarz bir sey calıstıracagım zaman ben hep bunu kullanırım
bir kotu tarafı Dos penceresini gizleyemiyor
Kod: Tümünü seç
function ExecWait(const Cmd: string): Integer;
var
ProcessInfo: TProcessInformation;
hProcess: THandle;
ReturnCode: Integer;
StartupInfo: TStartupInfo;
procedure ChkBool(Value: Boolean; const Msg: string);
begin
if (Value = false) then
raise exception.create(Msg);
end;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), 0);
ChkBool(CreateProcess(nil, PChar(Cmd), nil, nil, False,
CREATE_DEFAULT_ERROR_MODE + NORMAL_PRIORITY_CLASS,
nil, nil, StartupInfo, ProcessInfo),
'Error during CreateProcess');
hProcess := ProcessInfo.hProcess; // save the process handle
//Close the thread handle as soon as it is no longer needed
CloseHandle(ProcessInfo.hThread);
ReturnCode := WaitForSingleObject(hProcess, INFINITE);
ChkBool(dword(ReturnCode) <> WAIT_FAILED, 'Error in WaitForSingleObject');
// The process terminated
ChkBool(GetExitCodeProcess(hProcess, dword(Result)),
'Error in GetExitCodeProcess');
// Close the process handle as soon as it is no longer needed
ChkBool(CloseHandle(hProcess), 'Error in process Close Handle');
end;