不用翻,有现成的:
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;
//MyResult
WORD;
hStdIn:THandle; // standard input handle
//inputBuffer:INPUT_RECORD; //buffer to hold a single console input record
irMacroBuf:INPUT_RECORD; // array of input events
dwBytesWritten : DWORD;
begin
SetConsoleTitle('s');
StrPCopy(zAppName,FileName);
//MainForm.Caption := zappname;
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
hStdIn:= StartupInfo.hStdInput;
StartupInfo.hStdInput:= hStdIn;
StartupInfo.lpTitle:=@zAppName;
StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESTDHANDLES;
WriteConsoleInput(hStdIn,irMacroBuf,1,dwBytesWritten);
StartupInfo.dwFlags := StartupInfo.dwFlags or 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);
Result:=1;
end;
end;
其实非常简单,用不着这么复杂,用Winexec()或ShellExectute()就够了。