下面是一个函数,用于启动一个可执行文件,并传给启动参数(命令行),并等待它结束。<br>稍加改动就可以达到楼主的要求。把等待结束改为延时后关闭即可。<br>参数两个,前一个是可执行文件路径,后一个是命令参数。<br>注意可执行路径用ExtractShortPathName处理一下,要短文件名才行。<br>调用这个函数的例子:<br>M_wait_rar(ExtractShortPathName(extractfilepath(application.ExeName)+'rar.exe'),'x -o+ '+ss+' '+ss2);<br><br>//函数*****************************************************************<br>procedure M_wait_rar(M_filename1, M_cmd1: string);<br>var SUInfo: TStartupInfo;<br> ProcInfo: TProcessInformation;<br> CmdLine2: string;<br> result1: boolean;<br>begin<br> CmdLine2 := '"' + M_filename1 + '"' + M_cmd1; { 注意检查长文件名}<br> FillChar(SUInfo, SizeOf(SUInfo), #0);<br> with SUInfo do begin<br> cb := SizeOf(SUInfo);<br> dwFlags := STARTF_USESHOWWINDOW;<br> wShowWindow := sw_shownormal;<br> end;<br><br> Result1 := CreateProcess(nil, PChar(CmdLine2), NIL, NIL,<br> FALSE,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,<br> PChar(ExtractFilePath(M_filename1)), SUInfo, ProcInfo);<br> if Result1 then {等待结束 }<br> begin<br> WaitForSingleObject(ProcInfo.hProcess, INFINITE);<br> CloseHandle(ProcInfo.hProcess); {清理句柄 }<br> CloseHandle(ProcInfo.hThread);<br> end;<br><br>end;