关于调用CreateProcess(100分)

  • 主题发起人 主题发起人 luojun
  • 开始时间 开始时间
L

luojun

Unregistered / Unconfirmed
GUEST, unregistred user!
调用CreateProcess来执行dos程序总要弹出一个Dos窗口,<br>如何使窗口Hide或使窗口最小化。<br>我按帮助试了,可是不行<br>请给出列子!
 
lpStartupInfo.wShowWindow := SW_HIDE;<br>或者可用ShellExecute
 
要调用dos程序,使用shellexecute更方便<br>use shellapi;<br>code:=shellexecute(hwnd,'arj','-a test.arj *.*','.',SW_HIDE) //隐藏窗口<br>code:=shellexecute(hwnd,'arj','-a test.arj *.*','.',SW_MINIMIZE)<br>//最小化窗口<br><br><br>
 
参考如下程序<br>Function MyPing(const Host:string):boolean;<br>var<br>&nbsp; CmdLinePChar:array[0..120] of char;<br>&nbsp; StartUpInfo:TStartUpInfo;<br>&nbsp; ProcessInfo:TProcessInformation;<br>&nbsp; HOutput:THandle;<br>&nbsp; StringList:TStringList;<br>&nbsp; TempFileName:String;<br>&nbsp; i:integer;<br>begin<br>&nbsp; Result:=false;<br>&nbsp; Screen.Cursor:=crHourGlass;<br>&nbsp; StringList:=TStringList.Create;<br>&nbsp; try<br>&nbsp; &nbsp; TempFileName:=ExtractFilePath(application.ExeName)+'tempfile.tmp';<br>&nbsp; &nbsp; HOutput:=FileCreate(TempFileName);<br>&nbsp; &nbsp; if HOutput&lt;0 then<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; StrPCopy(CmdLinePChar,'Ping.exe'+Host);<br>&nbsp; &nbsp; FillChar(StartUpInfo,sizeof(StartUpInfo),#0);<br>&nbsp; &nbsp; with StartUpInfo do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; cb:=sizeof(StartUpInfo);<br>&nbsp; &nbsp; &nbsp; dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;<br>&nbsp; &nbsp; &nbsp; wShowWindow:=SW_HIDE;<br>&nbsp; &nbsp; &nbsp; hstdOutput:=HOutput;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if CreateProcess(nil,CmdLinePChar,nil,nil,True,0,nil,nil,StartUpInfo,ProcessInfo) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; WaitForSingleObject(Processinfo.hProcess,INFINITE);<br>&nbsp; &nbsp; &nbsp; FileClose(HOutput);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; FileClose(HOutput);<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; StringList.LoadFromFile(TempFileName);<br>&nbsp; DeleteFile(TempFileName);<br>&nbsp; for i:=1 to StringList.Count-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; if pos('Reply from',StringList)&gt;=1 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result:=true;<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; finally<br>&nbsp; screen.Cursor:=crDefault;<br>&nbsp; form1.edit1.text:=stringlist;<br>&nbsp; StringList.Free;<br><br>&nbsp; end;<br><br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>MyPing(' 172.18.128.1');<br>end;
 
接受答案了.
 
不行啊,在2000底下输出不到文件<br>
 
后退
顶部