在C ++中停止/启动过程 [英] Stop / Start Process In C++

查看:118
本文介绍了在C ++中停止/启动过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想停止浏览器并在c ++中重新开始。我可以从命令行执行此操作。有没有办法在C ++中执行此操作?



从命令提示
停止资源管理器
taskkill / F / IM explorer.exe
启动资源管理器
资源管理器





也许系统(c:\taskkill) / F / IM explorer.exe)







system(c:\ explorer)

解决方案

建议不要使用ShellExecute启动资源管理器。如果你进行一些测试,你可能会注意到使用该方法破坏了图标叠加和文件复制。



最可靠的方法是来自< stdlib的系统命令。 h>:

 system(  explorer); 



这相当于Run:explorer或任务管理器 - >开始新任务:资源管理器。



我无法相信有多少在线资源推荐ShellExecute导致开发人员花费数小时调试。


我会使用 ShellExecute(); 执行程序! :)



原因是我不喜欢系统();功能是因为它执行其他进程来完成程序任务,并且程序taskkill可能在每台PC上都不可用。例如,Windows XP Home Edition没有taskkill程序。



  #include   <   windows.h  >  
ShellExecute( 0 0 C:\\windows\\system32 \\ explorer.exe 0 0 ,SW_SHOWDEFAULT);< /windows.h>





使用ShellExecute函数,您可以指定程序的显示方式,如果要隐藏它或显示它最大化等等:)


I want to stop explorer and start again in c++. I can do this from the command line. Is there a way to do this in C++?

FROM THE COMMAND PROMPT
TO STOP explorer
taskkill /F /IM explorer.exe
TO START explorer
explorer



Perhaps system(c:\taskkill / F /IM explorer.exe)

and

system(c:\explorer)

解决方案

Using ShellExecute for starting explorer is not recommended. If you do some testing, you might notice that icon overlays and file copying are broken using that method.

The most reliable way is the system command from <stdlib.h>:

system("explorer");


This is the equivalent of Run: explorer or Task Manager->Start New Task: explorer.

I can't believe how many online sources recommend ShellExecute leading to hours of debugging for the developer.


I would use ShellExecute(); to execute a program! :)

The reason is that i dont like the System(""); function is because it executes other processes to accomplish your programs task and the program "taskkill" may not be avalible on every PC. For example Windows XP Home Edition dont have the "taskkill" program.

#include <windows.h>
ShellExecute(0, 0, "C:\\windows\\system32\\explorer.exe", 0, 0, SW_SHOWDEFAULT);</windows.h>



And with the ShellExecute function, you can specify how the program should be displayed, if you want to hide it or to show it maximized and so on :)


这篇关于在C ++中停止/启动过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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