<br>呵呵!给你一个功能更好的!<br>不仅能完成你所说的功能,而且能得到DOS程序的输出信息!<br>其中的CREATEPROCESS可以参考!给分吧!<br>其在用的是PIPE来得到输出信息!<br><br>function RunDOS(const Prog, CommandLine, Dir: string; out ExitCode: DWORD):<br> string;<br>var<br> HRead, HWrite: THandle;<br> StartInfo: TStartupInfo;<br> ProceInfo: TProcessInformation;<br> b: Boolean;<br> sa: TSecurityAttributes;<br> inS: THandleStream;<br> sRet: TStrings;<br>begin<br> Result := '';<br> FillChar(sa, SizeOf(sa), 0);<br> //设置允许继承,否则在NT和2000下无法取得输出结果<br> sa.nLength := SizeOf(sa);<br> sa.bInheritHandle := True;<br> sa.lpSecurityDescriptor := nil;<br> b := CreatePipe(HRead, HWrite, @sa, 0);<br> if not b then<br> raise Exception.Create(SysErrorMessage(GetLastError));<br> FillChar(StartInfo, SizeOf(StartInfo), 0);<br> StartInfo.cb := SizeOf(StartInfo);<br> StartInfo.wShowWindow := SW_HIDE;<br> //使用指定的句柄作为标准输入输出的文件句柄,使用指定的显示方式<br> StartInfo.dwFlags := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW;<br> StartInfo.hStdError := HWrite;<br> StartInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE); //HRe;<br> StartInfo.hStdOutput := HWrite;<br><br> b := CreateProcess(PChar(Prog), //lpApplicationName: PChar<br> PChar(CommandLine), //lpCommandLine: PChar<br> nil, //lpProcessAttributes: PSecurityAttributes<br> nil, //lpThreadAttributes: PSecurityAttributes<br> True, //bInheritHandles: BOOL<br> CREATE_NEW_CONSOLE,<br> nil,<br> PChar(Dir),<br> StartInfo,<br> ProceInfo);<br><br> CheckResult(b);<br> repeat<br> Application.ProcessMessages;<br> until WaitForSingleObject(ProceInfo.hProcess, 1) = 0;<br><br> GetExitCodeProcess(ProceInfo.hProcess, ExitCode);<br><br> inS := THandleStream.Create(HRead);<br> if inS.Size > 0 then<br> begin<br> sRet := TStringList.Create;<br> sRet.LoadFromStream(inS);<br> Result := sRet.Text;<br> sRet.Free;<br> end;<br> inS.Free;<br> CloseHandle(HRead);<br> CloseHandle(HWrite);<br>end;<br>