delphi 运行外部程序函数winexec WinExecAndWait32 CreateProcess

2016-11-12 11:12:00来源:oschina作者:依宸老爹人点击

第七城市

转载地址:/2014th7cj/d/file/p/20161112/bi1fxkmkgs2

运行外部程序但不需等待winexec


运行外部程序并等待外部程序结束才返回结果的函数


function WinExecAndWait32(FileName: string; Visibility: Boolean): integer; var zAppName: array[0..512] of char; //存放应用程序名 StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; exitCode: Dword; aVisibility: integer; beginStrPCopy(zAppName, FileName);FillChar(StartupInfo, Sizeof(StartupInfo), #0);//给StartupInfo结构体赋值 StartupInfo.cb := Sizeof(StartupInfo);StartupInfo.dwFlags := STARTF_USESHOWWINDOW;if Visibility thenaVisibility := 1 elseaVisibility := 0;StartupInfo.wShowWindow := aVisibility; //调用CreateProcess 创建进程,执行指定的可执行文件 if not CreateProcess(nil, zAppName, nil, nil, false , CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS , nil, nil, StartupInfo, ProcessInfo) then Result := -1 else begin //等待可执行文件退出 WaitForSingleObject(ProcessInfo.hProcess, INFINITE); //得到进程终止状态码 GetExitCodeProcess (ProcessInfo.hProcess, exitCode); result := exitCode; end; end;

第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台