Check if a specific exe file is running

murasaki5 picture murasaki5 · Nov 16, 2009 · Viewed 64.7k times · Source

I want to know how i can check a program in a specific location if it is running. For example there are two locations for test.exe in c:\loc1\test.exe and c:\loc2\test.exe. I only wanted to know if c:\loc1\test.exe is running and not all instances of test.exe.

Answer

bruno conde picture bruno conde · Nov 16, 2009
bool isRunning = Process.GetProcessesByName("test")
                .FirstOrDefault(p => p.MainModule.FileName.StartsWith(@"c:\loc1")) != default(Process);