Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2002.01.10;
Скачать: CL | DM;

Вниз

CreateProcess   Найти похожие ветки 

 
Shmel ©   (2001-11-08 21:15) [3]

Вот когда-то писал :)
function FileExecuteWait(outpath,temppath,base:string): Integer;
var
FileName, Params, StartDir: string;
Info: TShellExecuteInfo;
ExitCode: DWORD;
p:HWND;
begin
FileName:=temppath+"My.EXE";
Params:="";
StartDir:=outpath;
FillChar(Info, SizeOf(Info), 0);
Info.cbSize := SizeOf(TShellExecuteInfo);
with Info do begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(FileName);
lpParameters := PChar(Params);
lpDirectory := PChar(StartDir);
nShow := SW_Hide;
end;
if ShellExecuteEx(@Info) then begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(Info.hProcess, ExitCode);
p:=FindWindow("#32770", nil); // убивает возникающие окна с ошибками
if (p<>0) then begin
postmessage(p, wm_quit,0,0);
End;
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
Result := ExitCode;
end
else Result := -1;
end;

Можно еще и Так:

Function waitexec(outpath,temppath,base:string):Integer;
VAr Sp:TStartupInfo;
Pp:TProcessInformation;
Begin
FillChar(Pp,SizeOf(Pp),#0);
FillChar(Sp,Sizeof(Sp),#0);
Sp.cb := Sizeof(Sp);
Sp.dwFlags := STARTF_USESHOWWINDOW;
Sp.wShowWindow :=0; //DisplayMode;
chdir(Outpath);
if not CreateProcess(nil,
PChar(temppath+"My.EXE "+ "param"), { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
False, { handle inheritance flag }
CREATE_DEFAULT_ERROR_MODE or
CREATE_NEW_CONSOLE or { creation flags }
HIGH_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
Sp, { pointer to STARTUPINFO }
Pp) { pointer to PROCESS_INF }
then Begin
result:=-1;
end
else begin
WaitforSingleObject(Pp.hProcess,INFINITE);
GetExitCodeProcess(Pp.hProcess,Cardinal(Result));
CloseHandle(Pp.hProcess);
CloseHandle(Pp.hThread);
Pp.hProcess:=0;
Pp.hThread:=0;
end;
End;






Страницы: 1 вся ветка

Текущий архив: 2002.01.10;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.009 c
7-28547
harisma
2001-09-24 15:14
2002.01.10
Открытие и работа с портами в Win2000


6-28515
Woolen
2001-10-13 09:52
2002.01.10
Определение URL


4-28564
YUS
2001-11-09 08:04
2002.01.10
Создание Dll.


3-28418
Naile
2001-12-09 12:08
2002.01.10
IBX&Insert


14-28528
Васильев П.
2001-11-09 23:01
2002.01.10
Прибалтийцы и живущие в дальнем зарубежье!