简体   繁体   English

在Windows中重新启动进程[exe]

[英]Restart a process [exe] in Windows

I have a C++ exe; 我有一个C ++ exe; under a particular scenario I need to stop the exe and start it up again. 在特定情况下,我需要停止exe并重新启动它。 This has to be done from within the same exe and not from outside. 必须从同一exe内部而不是从外部完成。 What is the best way to achieve this? 实现此目标的最佳方法是什么?

My guess is to start a new instance of the process and then kill the running process. 我的猜测是启动流程的新实例,然后终止正在运行的流程。 But is there any straight forward API to do this, like RestartProcess() or something? 但是是否有任何简单的API可以做到这一点,例如RestartProcess()或其他东西? If not what do you suggest? 如果不是,您有什么建议?

No, there's no such built-in method. 不,没有这样的内置方法。 You really have to detect the path to the executable (GetCurrentModule(), then GetModuleFileName()), run the new process (CreateProcess()), then exit the current process (ExitProcess()). 您实际上必须先检测可执行文件的路径(GetCurrentModule(),然后是GetModuleFileName()),运行新进程(CreateProcess()),然后退出当前进程(ExitProcess())。

Use the standard exec function. 使用标准的exec函数。 it runs a program and does not return, in effect replacing the current running program with a new one. 它运行一个程序并且不返回,实际上是用一个新程序替换当前正在运行的程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM