当前位置: 动力学知识库 > 问答 > 编程问答 >

boost - stop external program from c++ code

问题描述:

Possible Duplicate:

How to effectively kill a process in C++ (Win32)?


I am creating a program that has to do an important task - and it may (rarely) have a resource conflict with another program (let's say a.exe) that users may have inadvertently started.
What I would like to do is kill a.exe if it is running, before doing the rest of the work.

Is there any way to stop another program/process from running, from c++ (running under Windows) ?

I was hoping that there may be something in the beautiful boost...

Thank you.

网友答案:

If you're sure the image name is a.exe then it's very simple:

system("taskkill /F /IM a.exe >nul 2>&1");
网友答案:

Assuming you are working on Windows.

You can use .NET methods. I will link you a post. http://stackoverflow.com/a/116098/1424790

If you need, I could translate the post into C++ (but I need some time for that).

网友答案:

It depends, if you're talking about Windows then you can either use taskkill as already stated, or you can use kernel32.dll's TerminateProcess method.

More info on that - http://msdn.microsoft.com/en-us/library/windows/desktop/ms686714(v=vs.85).aspx

If you're on *nix, it's as simple as using POSIX kill method found in signal.h.

More info on that - http://linux.die.net/man/2/kill oops, just properly read the question mentioning Windows

分享给朋友:
您可能感兴趣的文章:
随机阅读: