0

I have a function that checks to see if a given process is running and it works except for when that process has a tooltip open. If the process does have a tooltip open then this function returns false and i can't seem to figure out the problem.

public static bool isRunning(string progName, bool isId, int id)
{
    foreach (Process pro in Process.GetProcesses("."))
        if (isId)
        {
            if (pro.Id == id)
                return true;
        }
        else
        {
            if (pro.ProcessName == progName)
                return true;
        }

    return false;
}

An example of calling this function - isRunning("chrome.exe", false, -1) or isRunning("", true, 248). Is there something I am doing wrong or something else i need to check for?

Here is the full code for the file: http://ideone.com/9CUJ5V

EDIT: I partially solved my issue. I added this:

foreach(Process pro in Process.GetProcessesByName(progName)){
    if(pro.MainWindowHandle != (IntPtr)0)
        return true;

According to the msdn Documentation on Process.MainWindowHandle, it will return zero if it does not have a graphical interface.

But the next issue is, for example, if I am running steam minimized to the taskbar (so no window actually visible), it returns true.

73cn0109y
  • 75
  • 1
  • 10
  • Indeed after reading your post again, my comment is not applicable. Then I think that a process that is waiting for closing of the popup is not considered 'Running'. You may have to check some other System.Diagnostics classes and methods, like GetProcessesByName, to also get non-running process info. – Pieter21 Aug 02 '14 at 12:27
  • Alrite well ill try that tomorrow and ill report back here and tell ya if it works with some additional checks. – 73cn0109y Aug 02 '14 at 13:41
  • @Pieter21 I have pertially fixed it but I have a new problem now... – 73cn0109y Aug 03 '14 at 09:39

0 Answers0