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.