Современные решения

для защиты Windows приложений

и восстановления исходного кода
Автор: Robor. Дата публикации: 22.08.2004

Как запустить приложение и подождать пока оно отработает


Запускаю с помощью CreateProcess процесс архивирования, как узнать, что он завершился, чтобы перекопировать файл на дискету?

Unit exec; interface Uses Windows, SysUtils, Forms, ShellAPI; function ExecWin(Path,name,CommandLine,CurrentDir:string;Wait:boolean) : word; implementation function ExecWin(Path,name,CommandLine,CurrentDir:string;Wait:boolean) : word; var tsi : TStartupInfo; tpi : TProcessInformation; tPath,Command : PChar; CurDir :Pchar; // st1 :string; // T1,T2,T3,T4 :TFileTime; // rr :boolean; cod :DWord; // ErrorMessage: Pointer; // ErrorCode: DWORD; // holds a system error code begin Result := 30; Path:=path+name+' '+CommandLine+#00; CommandLine:=CommandLine+#0; tPath := StrAlloc(512); Command := StrAlloc(512); CurDir :=StrAlloc(512); FillChar(tsi, SizeOf(TStartupInfo), 0); tsi.cb := SizeOf(TStartupInfo); tsi.dwFlags := STARTF_USESHOWWINDOW; tsi.wShowWindow := SW_SHOWMINNOACTIVE; // FindExecutable(@Path[1],nil,tPath); // st1:=string(tPath)+#0; // st1:=AnsiUpperCase(st1); // Path:=AnsiUpperCase(Path); // if st1< > Path then st1:=Concat(st1,' ',path,#0); // Move(st1[1],tPath[0],Length(st1)); // Move(CommandLine[1],Command[0],length(CommandLine)); Move(Path[1],tPath[0],Length(Path)); CurrentDir:=CurrentDir+#0; Move(CurrentDir[1],CurDir[0],length(CurrentDir)); try if CreateProcess(nil,@tPath[0]{, @Command[0]},nil, nil, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,nil, @CurDir[0], tsi, tpi) then begin cod:=WAIT_TIMEOUT; while (cod=WAIT_TIMEOUT) and Wait do begin cod:=WaitForSingleObject(tpi.hProcess, 500); Application.ProcessMessages; end; result:=0; { rr:=GetProcessTimes(tpi.hProcess,t1,t2,t3,t4); while (t2.dwLowDateTime=0) and (t2.dwHighDateTime=0) and rr do begin Application.ProcessMessages; rr:=GetProcessTimes(tpi.hProcess,t1,t2,t3,t4); end;} CloseHandle(tpi.hProcess); CloseHandle(tpi.hThread); end else result:=GetLastError; finally { ErrorCode := GetLastError; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, nil, ErrorCode, 0, @ErrorMessage, 0, nil); LocalFree(hlocal(ErrorMessage));} StrDispose(Command); StrDispose(tPath); StrDispose(CurDir); end; end; end.



Комментарии

отсутствуют

Добавление комментария


Ваше имя (на форуме):

Ваш пароль (на форуме):

Комментарии могут добавлять только пользователи,
зарегистрированные на форуме данного сайта. Если Вы не
зарегистрированы, то сначала зарегистрируйтесь тут

Комментарий: