In my tool at a certain point I want to kill a process by it\'s name. I\'m testing now on Win7 64-bit, but the error I receive is:
A 32 bit processes cann
Use Process.GetProcessesByName(), which will in most cases by identical to looking for the name of (main) module. You will still have to deal with the fact, that this will return multiple processes,so you may or may not want to kill all of them, but, YMMV.
foreach (Process process in Process.GetProcessesByName("communicator"))
{
process.Kill();
}
Also note that the Kill
method runs asynchronously, i.e. it may return before the respective process has actually been killed. You could add a Process.WaitForExit()
if you care.