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
博客展示了WinExecAndWait32函数的代码实现,该函数接收文件名和可见性参数,返回整数结果。代码中涉及字符数组、进程信息结构体等操作,通过CreateProcess创建进程并等待其结束,最后获取退出代码作为结果。
4799

被折叠的 条评论
为什么被折叠?



