Форум: "Система";
Текущий архив: 2002.10.17;
Скачать: [xml.tar.bz2];
ВнизCreateProcess Найти похожие ветки
← →
BAY (2002-08-07 22:09) [0]А как лучше запустить win-прогу, и проконтролировать, когда сия закроется? (подозреваю, что CreateProcess это делает, но как с ним работать - не представляю)
← →
AlexXP (2002-08-08 02:24) [1]Ты угадал эта функция запускает процесс и выдаёт кучу инфы о нём, среди неё ести и Handle (дескриптор этого процесса).
Используй его в функции WaitForSingleObject.
///////////////////////////////////////////
The WaitForSingleObject function returns when one of the following occurs:
· The specified object is in the signaled state.
· The time-out interval elapses.
DWORD WaitForSingleObject(
HANDLE hHandle, // handle of object to wait for
DWORD dwMilliseconds // time-out interval in milliseconds
);
Parameters
hHandle
Identifies the object. For a list of the object types whose handles can be specified, see the following Remarks section.
Windows NT: The handle must have SYNCHRONIZE access. For more information, see Access Masks and Access Rights.
dwMilliseconds
Specifies the time-out interval, in milliseconds. The function returns if the interval elapses, even if the object"s state is nonsignaled. If dwMilliseconds is zero, the function tests the object"s state and returns immediately. If dwMilliseconds is INFINITE, the function"s time-out interval never elapses.
Return Values
If the function succeeds, the return value indicates the event that caused the function to return.
If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError.
The return value on success is one of the following values:
Value Meaning
WAIT_ABANDONED The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.
WAIT_OBJECT_0 The state of the specified object is signaled.
WAIT_TIMEOUT The time-out interval elapsed, and the object"s state is nonsignaled.
← →
Slava (2002-08-08 11:20) [2]http://delphibase.endimus.com/?action=viewtopic&topic=winappctrl
← →
SergeSV (2002-08-08 11:52) [3]Смотри - это точно работает
function ExecuteSomething(const ProgName, Cmd: String; Show: Word): DWORD;
var
sInf: TStartupInfo;
pInf: TProcessInformation;
Code: DWORD;
begin
Code := 0;
FillChar(sInf, SizeOf(sInf),0);
sInf.cb := SizeOf(sInf);
sInf.wShowWindow := Show;
sInf.dwFlags := STARTF_USESHOWWINDOW;
if CreateProcess(PChar(ProgName),PChar(Cmd), nil, nil, False, 0, nil, nil, sInf, pInf) then
while GetExitCodeProcess(pInf.hProcess, Code)
and (Code = STILL_ACTIVE) do
begin
Application.ProcessMessages;
Sleep(500);
end;
Result := Code;
CloseHandle(pInf.hThread);
CloseHandle(pInf.hProcess);
end;
← →
SergeSV (2002-08-08 12:01) [4]Ну да, и вызов:
ExecResult := ExecuteSomething(IShield, IShield+" -p"+IProject+" -m"+MediaType+" -b""+tempPath+"" "+lParams, SW_SHOWNORMAL);
{Вверху IShield = "C:\PROGRA~1\INSTAL~2\PROFES~1\Program\ISBuild.exe" второй параметр то же самое только с параметрами уже для IShield}
// Ниже просто обработка результата
if ExecResult = 0 then mResults.Lines.Add(" Compilation finished "+DateTimeToStr(Now)+" Return code: "+IntToStr(ExecResult)+" (No errors)")
else mResults.Lines.Add("Compilation finished "+DateTimeToStr(Now)+" Return code: "+IntToStr(ExecResult)+" See package log for details.");
mResults.Lines.Add("");
← →
Alx2 (2002-08-08 14:03) [5]Var
PInf : TProcessInformation;
StInfo : TStartupInfo;
begin
StInfo.dwFlags := STARTF_USESHOWWINDOW;
CreateProcess("filename.exe",<параметры>,Nil,Nil,
False,0,nil,nil,stInfo,PInf);
// Но сначала нужно проверить успешность запуска
WaitForSingleObject(PInf.hProcess,INFINITE);
end;
просто ждем окончания процесса, при этом совсем не загружаем процессор, в отличие от
"
SergeSV (08.08.02 11:52)
...........
while GetExitCodeProcess(pInf.hProcess, Code)
.......
"
Страницы: 1 вся ветка
Форум: "Система";
Текущий архив: 2002.10.17;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.006 c