如何在前台用户不觉察的前提下,在后台执行一个控制台的程序?(300分)

  • 主题发起人 主题发起人 extrinsic
  • 开始时间 开始时间
E

extrinsic

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个程序,主窗体中有一个按钮,按下它后,主窗体将执行一个后台的命令行程序,<br>并且等待该命令行程序结束之后,用对话框通知用户。现在的要求是,在整个执行过程中,<br>用户无法觉察到前台的窗体在调用后台程序,而是认为全部任务都是由前台窗体完成的(如<br>不会出现DOS窗口,不会返回后台命令行程序的输出信息等),请问这样的要求应该如何<br>实现。
 
查看CreateProcess的帮助
 
那就看你的后台程序有没有窗体和对话框之类的东东了,如果没有,完全可以不出现任何<br>效果的,用createprocess或winexec等都可以运行一个程序。
 
設成SW_HIDE方式運行就可以了……
 
to chenxz:<br>&nbsp; 我的后台程序是纯粹的命令行程序,执行过程中没有任何窗体和对话框。CreateProcess<br>的参数很多,请问具体怎么调用,能否给个例子?
 
没有delphi的了,给个bcb的,具体的看帮助<br><br>&nbsp; &nbsp; &nbsp; &nbsp; AnsiString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ProgramName;<br>&nbsp; &nbsp; &nbsp; &nbsp; AnsiString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ProgramPath;<br>&nbsp; &nbsp; &nbsp; &nbsp; STARTUPINFO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StInfo;<br>&nbsp; &nbsp; &nbsp; &nbsp; PROCESS_INFORMATION &nbsp; &nbsp; ProcInfo;<br>&nbsp; &nbsp; &nbsp; &nbsp; bool &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CreateCode;<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ProgramPath = AppPath;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ProgramName = AppPath + "abcde.exe";<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StInfo.cb = sizeof(StInfo);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StInfo.lpReserved = NULL;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StInfo.lpDesktop = NULL;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StInfo.lpTitle = NULL;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StInfo.dwFlags = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StInfo.cbReserved2 = NULL;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StInfo.lpReserved2 = NULL;<br><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CreateCode = CreateProcess(ProgramName.c_str(),NULL,NULL,NULL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; false,CREATE_NEW_CONSOLE,NULL,ProgramPath.c_str(),&amp;StInfo,&amp;ProcInfo);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (...)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!CreateCode)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(Handle,"启动失败","错误",MB_OK + MB_ICONERROR);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
 
后退
顶部