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...
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
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
More info on that - http://linux.die.net/man/2/kill oops, just properly read the question mentioning Windows