How do I kill the process exe with a specific location C#
<p>I have a requirement of killing an exe if I find an error in the log file and restart it again. The main problem here is, I cannot just delete the exe based on the name as I have the same exe running from different folders, such as D:\A\A1.exe and D:\B\A1.exe. I only want to delete the exe from "A" folder.</p>

<p>I have tried to follow Dirk Vollmar's Solution (<a href="https://stackoverflow.com/a/2238316/5159431">https://stackoverflow.com/a/2238316/5159431</a>).</p>

<p>to this question  - <a href="https://stackoverflow.com/questions/2237628/c-sharp-process-killing">C# Process Killing</a></p>

<p>But, when I debug his solution, I found that hModuleSnap Variable is invalid. </p>

<p><strong>Update - 1</strong></p>

<p>As Micky suggested, I have used Simon's Answer. It does kill the exe (Thanks for that). However, I am getting an error saying "System.ComponentModel.Win32Exception: Only part of a ReadProcessMemory or WriterocessMemory request was completed".</p>

<p>Here is the example code.</p>

<pre><code>string path1 = @"F:\Software\Application\Runner.exe";


        try
        {
            Process[] runningProcesses = Process.GetProcesses();

            foreach (Process process in runningProcesses)
            {
                // now check the modules of the process
                foreach (ProcessModule module in process.Modules)
                {
                    if (module.FileName.Equals(path1))
                    {
                        process.Kill();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
            Console.ReadLine();
        }
</code></pre>