请问如何让一个程序完全执行完毕后返回,WinExecAndWait32不中用! (50分)

  • 主题发起人 主题发起人 狼牙
  • 开始时间 开始时间

狼牙

Unregistered / Unconfirmed
GUEST, unregistred user!
WinExecAndWait32,winexec,shellexecurte都试过了,都不行,<br>下面是代码,如何让程序执行完setup.exe后继续执行下一条?<br>appparopath:='c:/temp/setup.exe';<br>//setup.exe是一个windows下面的安装程序,比如说delphi6的安装程序!!!<br>if fileexists(AppProPath) then<br>begin<br>&nbsp; WinExecAndWait32(AppProPath, 1);<br>end
 
function WinExecAndWait32(FileName:String; Visibility : integer):integer;<br>var<br>&nbsp; zAppName:array[0..512] of char;<br>&nbsp; zCurDir:array[0..255] of char;<br>&nbsp; WorkDir:String;<br>&nbsp; StartupInfo:TStartupInfo;<br>&nbsp; ProcessInfo:TProcessInformation;<br>&nbsp; //MyResult:DWORD;<br><br>&nbsp; hStdIn:THandle; // standard input handle<br>&nbsp; //inputBuffer:INPUT_RECORD; &nbsp;//buffer to hold a single console input record<br>&nbsp; irMacroBuf:INPUT_RECORD; // array of input events<br>&nbsp; dwBytesWritten : DWORD;<br><br>begin<br>&nbsp; SetConsoleTitle('s');<br>&nbsp; StrPCopy(zAppName,FileName);<br>&nbsp; //MainForm.Caption := zappname;<br>&nbsp; GetDir(0,WorkDir);<br>&nbsp; StrPCopy(zCurDir,WorkDir);<br>&nbsp; FillChar(StartupInfo,Sizeof(StartupInfo),#0);<br>&nbsp; StartupInfo.cb := Sizeof(StartupInfo);<br>&nbsp; hStdIn:= StartupInfo.hStdInput;<br>&nbsp; StartupInfo.hStdInput:= hStdIn;<br>&nbsp; StartupInfo.lpTitle:=@zAppName;<br>&nbsp; StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESTDHANDLES;<br><br>&nbsp; WriteConsoleInput(hStdIn,irMacroBuf,1,dwBytesWritten);<br><br>&nbsp; StartupInfo.dwFlags := StartupInfo.dwFlags or STARTF_USESHOWWINDOW;<br>&nbsp; StartupInfo.wShowWindow := Visibility;<br>&nbsp; if not CreateProcess(nil,<br>&nbsp; &nbsp; zAppName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ pointer to command line string }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to process security attributes }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to thread security attributes }<br>&nbsp; &nbsp; false, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { handle inheritance flag }<br>&nbsp; &nbsp; CREATE_NEW_CONSOLE or &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ creation flags }<br>&nbsp; &nbsp; NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to new environment block }<br>&nbsp; &nbsp; nil, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to current directory name }<br>&nbsp; &nbsp; StartupInfo, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { pointer to STARTUPINFO }<br>&nbsp; &nbsp; ProcessInfo) then Result := -1 { pointer to PROCESS_INF }<br><br>&nbsp; else begin<br>&nbsp; &nbsp; WaitforSingleObject(ProcessInfo.hProcess,INFINITE);<br>&nbsp; &nbsp; Result:=1;<br>&nbsp; end;<br>end;
 
楼上的,不行,setup.exe运行中就会继续下一步。
 
奇怪,是有些setup.exe可以等待,有些则不能,为什么?<br>都是安装程序噢,
 
排个队, 踢一脚
 
to 狼牙<br>确实 跟运行的程序本身有关系
 
多人接受答案了。
 
后退
顶部