CreateProcess -- by CJ(200分)

  • 主题发起人 主题发起人 CJ
  • 开始时间 开始时间
C

CJ

Unregistered / Unconfirmed
GUEST, unregistred user!
环境:Microsoft Windows 2000 Advanced Server<br>&nbsp; &nbsp; &nbsp; Borland Delphi 5 Pack #1 ADO Pack #2<br>&nbsp; &nbsp; &nbsp; InstallSheilder Express Limited Edition for Delphi 5 2.12<br>用以下函数调用InstallSheilder Express 制作的安装盘不能得到期望的效果<br>procedure ExecAndWait(Filename:String);<br>var<br>&nbsp; bCreateProcess: boolean;<br>&nbsp; lpStartupInfo: TStartupInfo;<br>&nbsp; lpProcessInformation: TProcessInformation;<br>begin<br>&nbsp; FillChar(lpStartupInfo, Sizeof(TStartupInfo), #0);<br>&nbsp; lpStartupInfo.cb := Sizeof(TStartupInfo);<br>&nbsp; lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br>&nbsp; lpStartupInfo.wShowWindow := SW_NORMAL;<br>&nbsp; bCreateProcess := CreateProcess(nil, PChar(Filename),<br>&nbsp; &nbsp; &nbsp; nil, nil, True, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; &nbsp; nil, nil, lpStartupInfo, lpProcessInformation);<br>&nbsp; if bCreateProcess then &nbsp; &nbsp; &nbsp;//Wait for exit<br>&nbsp; &nbsp; WaitForSingleObject(lpProcessInformation.hProcess, infinite);<br>end;<br><br>procedure TForm1.btnDataClick(Sender: TObject);<br>begin<br>&nbsp; ExecAndWait(DefaultPath + 'mdac_typ.exe');<br>end;<br><br>procedure TForm1.btnRecoverClick(Sender: TObject);<br>begin<br>&nbsp; ExecAndWait(DefaultPath + 'BININST/SETUP.EXE');<br>end;<br><br>procedure TForm1.btnClearDataClick(Sender: TObject);<br>begin<br>&nbsp; ExecAndWait(DefaultPath + 'DATAINST/SETUP.exe');<br>end;<br><br>procedure TForm1.btnFullClick(Sender: TObject);<br>begin<br>&nbsp; &nbsp; btnRecover.Click;<br>&nbsp; &nbsp; btnClearData.Click;<br>&nbsp; &nbsp; btnData.Click;<br>end;<br>被调用的SETUP程序不被执行,而我的程序也死,强行结束之,setup执行了...
 
会不会是这样:<br>Createprocess返回TRUE,但此时子进程(setup)还未初始化完毕,(你知道,<br>Createprocess在子进程进入main时就返回了),而SETUP和父进程有死锁的地方(猜测),<br>WaitForSingleObject把父进程挂气,等子进程终止,所以就。。。
 
或者是不能用CREATE_NEW_CONSOLE吧<br><br>另外install shield做的setup.exe好象是windows16位的程序,而且它启动了另外一个进程<br>后就立即退出了
 
&nbsp;SORRY, I CAN ONLY USE ENGLISH IN MY OFFICE, BECAUSE SO MANY "LING DAO :" :-)<br><br><br>&nbsp; // I've said, I always deal with concrete matters relating to work, so I give up the <br>&nbsp; // CreateProcess... In fact, in my mind, we cannot use such a way. Because InstallSheilder<br>&nbsp; // is playing a trick for us. As we know, <br>&nbsp; // The setup.exe unpack some file, which is known as InstallSheilder Wizard, to the temp <br>&nbsp; // directory, then it start the wizard and terminate itself. So, if we wait setup.exe <br>&nbsp; // successfully by WaitForSimpleObject, when the installation interface apears, <br>&nbsp; // the WaitForSimpleObject returned. It shows why WINRAR cannot run setup program made by<br>&nbsp; // InstallSheilder currectly. And why winzip need we to click 'ok' button to finish setup.<br>&nbsp; // Now, I use a "silly" way to finish my work.<br>&nbsp; // We use spy++ in Microsoft Visual Studio to find the window class, and wait for both 2<br>&nbsp; // program(preparing program and the installsheilder wizard) terminate.<br>&nbsp; // Now, my work finished, but I cannot prove why the setup program does not run. perhaps <br>&nbsp; // you are right, but WinRAR doesn't have such a problem, it really runs though it's not<br>&nbsp; // currect... but anyway, the problem solved. thanx all of you.<br>&nbsp; // The following is my key code:<br><br>&nbsp; if WinExec(pchar(Filename), SW_SHOWNORMAL) &gt; 31 then &nbsp; &nbsp; &nbsp;//if successful<br>&nbsp; begin<br>&nbsp; &nbsp; //In fact, On my computer, without the following sleep is acceptable<br>&nbsp; &nbsp; //Because before winexec return, the window is created.<br>&nbsp; &nbsp; //But I'm really not sure...<br>&nbsp; &nbsp; Sleep(10);<br>&nbsp; &nbsp; //here, we use the most easy, sily and poor-performance way to finish our work<br>&nbsp; &nbsp; //To avoid the white screen, we use Application.ProcessMessages;<br>&nbsp; &nbsp; //We use Microsoft spy++ to find the window class<br>&nbsp; &nbsp; //InstallShield_Win is the class for Setup program<br>&nbsp; &nbsp; //InstallShieldSetup30 is the class for unpacking window(is preparing InstallSheilder Wizard... )<br>&nbsp; &nbsp; while (FindWindow('InstallShield_Win',nil) &lt;&gt; 0) or<br>&nbsp; &nbsp; &nbsp; &nbsp;(FindWindow('InstallShieldSetup30',nil) &lt;&gt; 0) do<br>&nbsp; &nbsp; &nbsp; Application.ProcessMessages;<br>&nbsp; end;
 
没人有兴趣?浪费我感情啊,写那么多注释...
 
CJ:<br>&nbsp; 你的方法管用,但我用你一开始的代码,发现WaitForSingleObject无法返回而不是<br>象你说的那样INSTALL出来了就返回,程序在这儿组塞住了,看样子似乎Installshield<br>的进程用到了父进程的消息队列,WaitForSingleObject把父进程挂气等于把挂气了俩。<br>
 
yang2000, 我第一贴说了:<br>&gt;被调用的SETUP程序不被执行,而我的程序也死,强行结束之,setup执行了
 
后退
顶部