中国开发网: 论坛: 程序员情感CBD: 贴子 31290
pcplayer: WinExec and Wait from TurboPower
function WinExecAndWait32(FileName : PChar; CommandLine : PChar;
Visibility : Integer) : Integer;
{ returns -1 if the Exec failed, otherwise returns the process' exit
code when the process terminates }
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:ShortString;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
Temp : DWORD;
begin
StrCopy(zAppName, FileName);
StrCat(zAppName, CommandLine);
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 { pointer to PROCESS_INF }
Result := -1
else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess,Temp);
Result := Integer(Temp);
end;
end;

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录