Вы можете начать с создания словаря процессов с использованием WMI и FileVersionInfo.
private static IList<ProcessInfo> BuildProcessDictionary()
{
var wmiQueryString = "SELECT ProcessId, ExecutablePath FROM Win32_Process";
using (var searcher = new ManagementObjectSearcher(wmiQueryString))
using (var results = searcher.Get())
{
var processList = from p in Process.GetProcesses()
join mo in results.Cast<ManagementObject>()
on p.Id equals (int)(uint)mo["ProcessId"]
select new ProcessInfo
{
Process = p,
Path = (string)mo["ExecutablePath"],
DisplayName = (string)mo["ExecutablePath"]!=null?FileVersionInfo.GetVersionInfo((string)mo["ExecutablePath"]).FileDescription:string.Empty
};
return processList.ToList();
}
return default;
}
public class ProcessInfo
{
public string Path { get; set; }
public string DisplayName { get; set; }
public Process Process { get; set; }
}
Затем вы можете запросить коллекцию
var processDictionary = BuildProcessDictionary();
var found = processDictionary.Where(x => x.DisplayName!=null && x.DisplayName.Equals("Google Chrome"));
Обновление
var listOfPrograms = new[] { "Google Chrome", "Notepad" };
var processDictionary = BuildProcessDictionary();
foreach (var item in listOfPrograms)
{
try
{
var programInstances = processDictionary.Where(x => x.DisplayName != null && x.DisplayName.Equals(item));
foreach (var programInstance in programInstances)
{
programInstance.Process.Kill();
}
}
catch (Exception )
{
// Log items that wasn't found or coudn't be killed.
Console.WriteLine($"Could not find or kill process {item}");
}
}