You will need to study the properties of each module "Modules" and, in turn, check the file names in your desired path.
Here is an example:
Vb.net
Dim path As String = "C:\Program Files\Ultrapico\Expresso\Expresso.exe" Dim matchingProcesses = New List(Of Process) For Each process As Process In process.GetProcesses() For Each m As ProcessModule In process.Modules If String.Compare(m.FileName, path, StringComparison.InvariantCultureIgnoreCase) = 0 Then matchingProcesses.Add(process) Exit For End If Next Next For Each p As Process In matchingProcesses p.Kill() Next
FROM#
string path = @"C:\Program Files\Ultrapico\Expresso\Expresso.exe"; var matchingProcesses = new List<Process>(); foreach (Process process in Process.GetProcesses()) { foreach (ProcessModule m in process.Modules) { if (String.Compare(m.FileName, path, StringComparison.InvariantCultureIgnoreCase) == 0) { matchingProcesses.Add(process); break; } } } matchingProcesses.ForEach(p => p.Kill());
EDIT: Updated code to account for case sensitivity for string comparisons.
Ahmad mageed
source share