如何从另一个exe调用1 exe [英] how to call 1 exe from another exe

查看:76
本文介绍了如何从另一个exe调用1 exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

i有2个exe的

exe1:checklist.exe

exe2:reboot.exe



都是用C ++代码编写的。

现在我的exe1检查所有标准,如活动用户,进程,服务,如果每件事都按照要求罚款那么它必须重新启动我的exe2所做的系统。





现在我面临的问题是如何将两个exe链接在一起。更确切地说我想从exe1调用exe2。

所以如何在checklist.exe中编码调用reboot.exe





这里是我尝试的代码,但似乎效果不佳。

hi guys,
i have 2 exe's
exe1:checklist.exe
exe2:reboot.exe

both are written in C++ code.
now my exe1 check all the criteria like active users, processes,services and if every thing is fine as per requirement then it must reboot the system which my exe2 does.


now the problem i am facing is that how to i link both exe together. to be more precise i want to call exe2 from exe1.
so how do i code in checklist.exe which will call reboot.exe


here is the code i tried but seems not working well.

STARTUPINFO si = { sizeof(STARTUPINFO) };
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_HIDE;
	PROCESS_INFORMATION pi;
	CreateProcess("D:\\Autorbtchklst\\Release\\reboot.exe", NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);







imp note:

我的exe2即reboot.exe也执行




imp note:
my exe2 i.e reboot.exe also accept 1 parameter while executing

推荐答案

引用:

但接受1参数但似乎效果不佳。

but seems not working well.

这不是很有用。





如果你需要将参数传递给创建的进程,那么正确构建 lpCommandLine CreateProcess 的参数。您可以在文档中找到示例代码: MSDN上的CreateProcess [ ^ ]。

That's not pretty informative.


If you need to pass arguments to the created process then properly build the lpCommandLine argument of CreateProcess. You may find sample code in the very documentation: CreateProcess at MSDN[^].


如果您不想与第二个程序通信,只需调用 system http://www.cplusplus.com/reference/cstdlib/system/ [ ^ ]。你只需要注意你的第二个程序在搜索路径中,否则,提供完整的路径。



我不确定如果你的系统会发生什么调用尝试在主进程仍处于活动状态时重启计算机(并等待子进程完成),但您也可以编写一个小的DOS批处理文件,启动重新启动并立即完成,然后只需调用批处理文件。见这里: http://stackoverflow.com/questions/324539/how-can-i-run-a-program-from-a-batch-file-without-having-the-console-open-after [ ^ ]
If you don't want to communicate with your second program, you can just call system: http://www.cplusplus.com/reference/cstdlib/system/[^]. You only need to take care that your second program is in the search path, or else, provide the full path.

I'm not sure what happens if your system call attempts to reboot the machine while the main process is still active (and waiting for your child process to finish), but you could also write a small DOS batch file that starts the reboot and finishes immediately, and then just call the batch file. See here: http://stackoverflow.com/questions/324539/how-can-i-run-a-program-from-a-batch-file-without-having-the-console-open-after[^]


如何从另一个exe调用1个exe



how to call 1 exe from another exe

use WinExec


这篇关于如何从另一个exe调用1 exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆