首页  编辑  

执行一个外部程序并等待它的完成

Tags: /超级猛料/OS.操作系统/Process.进程/   Date Created:

Function WinExecExW(cmd,workdir:pchar;visiable:integer):DWORD;

var

StartupInfo:TStartupInfo;

ProcessInfo:TProcessInformation;

begin

FillChar(StartupInfo,SizeOf(StartupInfo),#0);

StartupInfo.cb:=SizeOf(StartupInfo);

StartupInfo.dwFlags:=STARTF_USESHOWWINDOW;

StartupInfo.wShowWindow:=visiable;

if not CreateProcess(nil,cmd,nil,nil,false,Create_new_console or Normal_priority_class,nil,nil,StartupInfo,ProcessInfo) then

  result:=0

else

begin

  waitforsingleobject(processinfo.hProcess,INFINITE);

  GetExitCodeProcess(ProcessInfo.hProcess,Result);

end;

end;