-1

Is there a way to check (using C#) whether there is an instance of an EXE that is refered to by path running? If so, please provide the method of doing so. Thank you in advance.

Example: Is there a way to find out if "C:\foo\bar.exe" has a running instance, by refering to the EXE as "C:\foo\bar.exe"?

1 Answers1

1

Do you want something like that;

public List<Process> GetProcessesByFileName(string fileName)
{
    return Process.GetProcesses().Where(x => x.MainModule.FileName == fileName).ToList();
}
lucky
  • 12,734
  • 4
  • 24
  • 46
  • While this looks good in theory it will in many instances throw an Access denied exception unless the process is running with elevated privileges. It would be better to use an old-fashioned loop with a try/catch embedded to handle this case. – Lasse V. Karlsen Nov 18 '17 at 19:48