1

I searched quite a few answers in StackOverflow but can't make it work.

This is my code:

bool Active = Process.GetProcessesByName("EXENAME").Any();

as you can see 'ACTIVE' gets true when the process "EXENAME" is running, but I want it more precise, I want to keep it in False state if the process "EXENAME" is running under System as well.

Please help!

mike
  • 100
  • 10
  • 1
    Perhaps this will help you. This is a tip using WMI http://stackoverflow.com/a/777567/3877877 – Martin E Jan 12 '17 at 23:16
  • 2
    Unrelated, but your can simplify your code (and make it far more clear) by changing `.FirstOrDefault(...) != default(Process)` to `.Any(...)` – Rob Jan 12 '17 at 23:17
  • @Rob I Simplified it :) Thanks for the advice – mike Jan 12 '17 at 23:34
  • @Mike No worries - but you still need the predicate inside `Any()` :). It should be: `.Any(p => p.MainModule.FileName.StartsWith(Environment.GetEnvironmentVariable("windir")))` to keep the same logic you had before – Rob Jan 12 '17 at 23:35
  • @Rob That's cool, don't need to check the path anymore, the only issue is to figure out the owner is "system" or not :( – mike Jan 12 '17 at 23:39
  • @Slai Where should I put that Mate? – mike Jan 12 '17 at 23:39

0 Answers0