Problem
I am trying to differentiate these google chrome processes from one another via there main window title. I know that some google chrome processes are processes that run within the background with no window, and therefore should return a main window title of an empty string. But, I can't make sense of why processes that are specifically windows are also returning empty strings as output onto my console when they clearly have a main window title.
Research
I have done some research about some of the possible reasons these other window related processes are returning empty strings at https://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowtitle%28v=vs.110%29.aspx , but am unsure if the remarks section of the website applies to my situation.
Here are the remarks section from the website
A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window (so that MainWindowHandle is zero), MainWindowTitle is an empty string (""). If you have just started a process and want to use its main window title, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created. Otherwise, the system throws an exception.
The main window is the window that currently has the focus; note that this might not be the primary window for the process. You must use the Refresh method to refresh the Process object to get the current main window handle if it has changed. Win98WinMe
My Case
To save everyone's time, I won't go into too much detail about what my application is trying to accomplish, besides that my goal at the moment is to further differentiate process ID's that happen to have the same process name.
For example,
And here's the code
// Get all instances of Chrome running on the local computer.
// This will return an empty array if Chrome isn't running.
array<Process^>^localByName = Process::GetProcessesByName("chrome");
// Print out each individual processes Process Name, ID, and Window Title
for each (Process^ p in localByName)
{
Console::WriteLine("Process: {0} ID: {1}, Main window title: {2} ", p->ProcessName, p->Id, p->MainWindowTitle);
}
Questions
- Can someone identify if the reason why I'm getting empty strings is related to how MainWindowTitle variable works, or if it has to do with the OS, or something else?
- Are there alternatives to getting all of the MainWindowTitle's for each of my Chrome processes?
- This question is kind of a mesh of question 1 and question 2, but I would really appreciate if someone can explain why the google chrome process that is active is the only case where it prints out a non-empty string. Live examples provided below
Example 1 : NFL.com active
Example 2 : Google.com active
Application Environment
OS : Windows 8.1
Programming Language : C++
IDE : Microsoft Visual Studio 2012