[Tips]挂起 - 运行外部程式,外部程式退出 - 继续执行

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

function WinExecAndWait32(FileName:String; Visibility : integer):integer;

var

zAppName : array[0..512] of char;

zCurDir : array[0..255] of char;

WorkDir : String;

StartupInfo:TStartupInfo;

ProcessInfo:TProcessInformation;

lpExitCode : Cardinal;

begin

StrPCopy(zAppName, FileName);

GetDir(0, WorkDir);

StrPCopy(zCurDir,WorkDir);

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

StartupInfo.cb := Sizeof(StartupInfo);

StartupInfo.dwFlags := STARTF_USESHOWWINDOW;

StartupInfo.wShowWindow := Visibility;

if not CreateProcess(nil,

zAppName, { pointer to command line string }

nil, { pointer to process security attributes }

nil, { pointer to thread security attributes }

false, { handle inheritance flag }

CREATE_NEW_CONSOLE or { creation flags }

NORMAL_PRIORITY_CLASS,

nil, { pointer to new environment block }

nil, { pointer to current directory name }

StartupInfo, { pointer to STARTUPINFO }

ProcessInfo) then Result := -1 { pointer to PROCESS_INF }

else begin

WaitforSingleObject(ProcessInfo.hProcess,INFINITE);

GetExitCodeProcess(ProcessInfo.hProcess, lpExitCode);

Result := lpExitCode;

end;

end;

整理:lzcx

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航