批量执行可运行程序 小工具太多,想做个类似于批量处理数据的批量运行可执行文件(.exe),关键点是:1 如何让代码去实现执行exe程序,而不是手动去双击该执行程序;2 如何知道exe已经开始运行及已经运行完成了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1:用ShellExecute。2:判断进程,查找窗体等等........ 用ShellExecuteEx(或者用CreateProcess)函数来执行每个exe程序,该函数的参数lpExecInfo成员hProcess表示进程句柄,用函数WaitForSingleObject 等待进程结束,然后再执行下一个exe程序 1.winexec,createprocess,system等都可以2.ls说的都可以 SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "E:\\运行程\\check.exe"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess, INFINITE);并没使得check.exe正常运行完才结束,而是很快就结束了 现在的麻烦是在开始执行ShellExecute的同时exe程序就立马结束了 在我机器上测试正常,ShellExecuteEx函数执行正确吗? SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "E:\\运行程\\check.exe"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess, INFINITE);代码是可以的,是你的程序很快就结束了,你找个有界面的试试,符合你的需要。 控制台也可以ShellExecute(NULL, _T("open"), _T("F:\\vc6.0\\全中文-MFC类库详解.chm"), NULL, NULL, SW_SHOWNORMAL); win32下hProcess不能wait,会马上返回。一个办法是搞些16位的东西进去。如果exe是自己写的就好办了,退出时signal一个命名事件即可。 http://support.microsoft.com/kb/125212/EN-US 控制台的可以先做一个bat , 再在程序里 system("your.bat"); SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "E:\\运行程\\check.exe"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess, INFINITE); 对执行对话框和文档型的exe都没有问题,就是对付控制台的没效果。使用bat也没效果,出现的描述如下:this application has requested the Runtime to terminate it in an unusual way. 网络游戏设计,斗地主 何如提取特征点? 怎样在按钮上贴图 如何实现树控件的遍历,给各例子好吗 在线等候:实时数据库方法及实现(VC) HTTP CLILEN T 问题(XMLHTTP问题) 设计好一个对话框后,怎样显示? WORD文档中ACtivex持久化问题--添加ACtivex对应数据流 指定 ISTREAM的名称 如何在win32中删除一个菜单 属性表里的字体大小为什么不能改变? vc项目汉化 Visual C++ 不能自动execute
2:判断进程,查找窗体等等........
2.ls说的都可以
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "E:\\运行程\\check.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
并没使得check.exe正常运行完才结束,而是很快就结束了
在我机器上测试正常,ShellExecuteEx函数执行正确吗?
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "E:\\运行程\\check.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);代码是可以的,是你的程序很快就结束了,你找个有界面的试试,符合你的需要。
ShellExecute(NULL, _T("open"), _T("F:\\vc6.0\\全中文-MFC类库详解.chm"), NULL, NULL, SW_SHOWNORMAL);
一个办法是搞些16位的东西进去。
如果exe是自己写的就好办了,退出时signal一个命名事件即可。
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "E:\\运行程\\check.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
this application has requested the Runtime to terminate it in an unusual way.