Here is method which must return processes by path to executeble file.
But when i try to call this method i have an exception Win32Exception “Access is denied”.
So how to do it right?
private static List<Process> GetProcessByFilename(string filename)
{
List<Process> processes = new List<Process>();
foreach (var process in Process.GetProcesses())
{
if (process.MainModule.FileName == filename)
{
processes.Add(process);
}
}
return processes;
}
You will get
Win32Exceptionwhen trying to getMainModuleof core system processes (see comments on MSDN). You should handle that.