Programı çalıştırmak ve bitene kadar beklemek
csyasar30.04.2004 - 15:49:11
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);
 
NOT : Bu sayfa google'un siteyi indekslemesi içindir. www.delphiturkiye.com/forum/ adresini kullanınız!
1998-2006 www.delphiturkiye.com