cmd运行的问题请教

hyrongg 2005-08-31 10:02:54
我循环调用ShellExecute(".exe",""),
for int i:=0 to 10 do
begin
ShellExecute(".exe","","");
End;

因为我的exe文件里面会有运行Cmd的命令,所以每次ShellExecute就会有cmd的窗体弹出来,有什么办法等一个exe完全运行完毕再进行下一个ShellExecute的操作?
...全文
169 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
leonkim 2005-09-01
  • 打赏
  • 举报
回复
class function SynchroExecute(const AExecutedFileName: string;
const AWaitTime: Integer; const AIsShow: Boolean): Boolean;
var
stinfo:TStartupInfo;
psinfo:TProcessInformation;
sap,sat:TSecurityAttributes;
begin
Result:=False;
stinfo.dwFlags:=STARTF_USESHOWWINDOW;
stinfo.cbReserved2:=0;
stinfo.lpReserved:=nil;
stinfo.lpReserved2:=nil;
stinfo.lpDesktop:=nil;
if not AIsShow then
stinfo.wShowWindow:=SW_HIDE
else
stinfo.wShowWindow:=SW_SHOWNORMAL;
stinfo.cb:=SizeOf(TStartupInfo);

sap.lpSecurityDescriptor:=nil;
sap.bInheritHandle:=True;
sap.nLength:=SizeOf(TSecurityAttributes);
sat.lpSecurityDescriptor:=nil;
sat.bInheritHandle:=False;
sat.nLength:=SizeOf(TSecurityAttributes);

if FileExists(AExecutedFileName) and
CreateProcess(PChar(AExecutedFileName),'',@sap,@sat,False,NORMAL_PRIORITY_CLASS,nil,PChar(ExtractFilePath(ExpandFileName(AExecutedFileName))),stinfo,psinfo) then
begin
CloseHandle(psinfo.hThread);
Result:=WaitForSingleObject(psinfo.hProcess,AWaitTime) = WAIT_OBJECT_0;
CloseHandle(psinfo.hProcess);
end
else begin
RaiseLastOSError;
end;
end;
XY.Chen 2005-09-01
  • 打赏
  • 举报
回复
能不能生成一个批处理以后再运行?命令行下的start wait可以等待一个程序运行结束了再执行下面的程序。。。
leonkim 2005-09-01
  • 打赏
  • 举报
回复
不用ShellExecute
Dlwxn 2005-09-01
  • 打赏
  • 举报
回复
参考这个程序,应用程序也适用的:
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=104460
hyrongg 2005-09-01
  • 打赏
  • 举报
回复
for int i:=0 to 10 do
begin
ShellExecute(0, 'Open', PChar('c:\sendmail.exe'), PChar('-fi ' + sTempFile), nil,SW_SHOWNORMAL);
End;

sTempFile是我要用的参数。
因为我的exe文件里面会有运行Cmd的命令,所以每次ShellExecute就会有cmd的窗体弹出来,有什么办法等一个exe完全运行完毕再进行下一个ShellExecute的操作?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧