Mega Code Archive

 
Categories / Delphi / System
 

Program calistirmak ve bitene kadar beklemek

function RunProcess(const AppPath:string; MustWait: Boolean; AppParams: string; Visibility: Word):DWORD; var SI: TStartupInfo; PI: TProcessInformation; Proc: THandle; zFileName, zParams: array[0..79] of Char; begin FillChar(SI, SizeOf(SI), 0); SI.cb := SizeOf(SI); SI.wShowWindow := Visibility; if not CreateProcess(StrPCopy(zFileName, AppPath), StrPCopy(zParams, AppParams), nil, nil, false, Normal_Priority_Class, nil, nil, SI, PI) then raise Exception.CreateFmt('Failed to excecute program ' + AppPath + '. Error Code %d', [GetLastError]); Proc := PI.hProcess; CloseHandle(PI.hThread); if MustWait then if WaitForSingleObject(Proc, Infinite) <> Wait_Failed then GetExitCodeProcess(Proc, Result); CloseHandle(Proc); end; // Kullanimi: RunProcess('notepad.exe', True, '', SW_SHOWNORMAL);