I'm trying to get the list of all the open applications. Specifically, if you open the task manager and go to the applications tab, that list.
I've tried using something like this:
foreach (var p in Process.GetProcesses())
{
try
{
if (!String.IsNullOrEmpty(p.MainWindowTitle))
{
sb.Append("
");
sb.Append("Window title: " + p.MainWindowTitle.ToString());
sb.Append("
");
}
}
catch
{
}
}
Like in a few examples I've found, but this doesn't pull all the applications for me. It's only grabbing about half the ones I can see in the task manager or that I know I have open. For example, this method doesn't pick up Notepad++ or Skype for some reason, but DOES pick up Google Chrome, Calculator, and Microsoft Word.
Does anyone know either why this isn't working correctly or how to do so?
Also, a friend suggested it might be a permissions issue, but I am running visual studio as administrator and it hasn't changed.
EDIT: The problem I'm getting is that most of the solutions I've been given just returns a list of ALL processes, which isn't what I want. I just want the open applications or windows, like the list that appears on the task manager. Not a list of every single process.
Also, I know there is bad code in here, including the empty catch block. This was a throwaway project just to figure out how this works in the first place.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…