none
Windows 10: how to get list of foreground applications as in the task manager RRS feed

  • Question

  • Hi, 

    I want to get a list of foreground applications as categorized as "Apps" the the task manager.

    I did this:

    namespace WMISample
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                Process[] processes = Process.GetProcesses();
                foreach (var proc in processes)
                {
                    if (!string.IsNullOrEmpty(proc.MainWindowTitle) && proc.)
                    {
                        Console.WriteLine(proc.MainWindowTitle);
                    }
                }
    
                Console.Read();
            }
        }
    }

    If I check the mainwindowtitle, I would also get some background apps:

    Store
    Store
    Photos
    C:\Users\MeMeMe\Desktop\WMISample.exe

    However:

    Store is not running in the foreground.  It is a background processes according to the task manager.

    Ditto for Photos.

    How do I eliminate and correctly identify some as the background process, while others as the Apps as in task manager?

    Thanks!


    • Edited by neondeion Friday, February 26, 2016 10:36 PM
    Wednesday, February 24, 2016 1:01 AM

All replies

  • Hi neondeion,

    >>Store is not running in the foreground.  It is a background processes according to the task manager.

    Ditto for Photos.

    I've tested your code on my side in win10 machine. I don't know what Store is. But I used photo project to test.

    Photos is not background process.

    Please also show your screen capture or some more details.

    By the way, I see your title used WMI, but I don't think your case related to WMI. Or I misunderstood you, please let me know.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Wednesday, February 24, 2016 7:10 AM
    Wednesday, February 24, 2016 7:07 AM
  • Sorry for the title - I started out using WMI API to do this, but ended up using System.Diagnostics.Process.

    I am ok with either way if we can make it work.

    In your task manager, if you choose View -> Group by type, you'll see Apps category.

    So basically I know my program didn't do the job...  What I really want is

    * Store
    * Photos
    * Settings 

    NOT show up - and I would like to find out how to properly filter Store/Photo/Settings out from my code - because Apps section doesn't have it.

    Thanks!



    • Edited by neondeion Wednesday, February 24, 2016 10:54 PM
    Wednesday, February 24, 2016 9:40 PM
  • Hi neondeion,

    I tested again. It still works on my side. Check Settings in the following picture.

    I also checked thread How to get running applications in windows? [duplicate] your code should work.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Thursday, February 25, 2016 8:09 AM
    Thursday, February 25, 2016 8:07 AM
  • Hi Kristin

    I am on Win10 1511.

    Ok here's what I found:

    1. Settings - If I run Settings - Update, even though I close the foreground window, app seems to be still running in the background (shown as Background Processes)

    2. Ditto for Windows.Mobile.Store.  Download some store app and cancel.  Then close the foreground window.  app seems to be still running in the background (shown as Background Processes)

    If that is the case, maybe let me rephrase my question:

    a) Is there some WMI api or System.Diagnostics.Process attribute to distinguish whether it is a background process or foreground process?

    b) I don't think this API is a good way to tell whether a process is an App or Background Process per Task Manager.

    string.IsNullOrEmpty(proc.MainWindowTitle)


    Thanks!

    Thursday, February 25, 2016 7:15 PM
  • Hi neondeion,

    >>1. Settings - If I run Settings - Update, even though I close the foreground window, app seems to be still running in the background (shown as Background Processes)

    After you close this Setting window, have you restart your program? It should be restart again. Then setting will not in it. Please also check my test picture.

    >>a) Is there some WMI api or System.Diagnostics.Process attribute to distinguish whether it is a background process or foreground process

    No, after searching more, as far as I know, there is no WMI to achieve this.

    By the way, here is my system information.

    I also tested in win8.1, all the result are the same. Per my understanding, using above code could get running applications in windows like the same as App process.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Friday, February 26, 2016 3:03 AM
    Friday, February 26, 2016 3:03 AM
  • Suspended apps would also have the MainWindowTitle - so the API above is not a good indication as "What apps are running in the foreground."


    • Marked as answer by neondeion Friday, February 26, 2016 9:34 PM
    • Edited by neondeion Monday, February 29, 2016 7:10 PM
    • Unmarked as answer by neondeion Monday, February 29, 2016 7:10 PM
    Friday, February 26, 2016 8:33 PM
  • Hi neondeion,

    As far as I know, unfortunately, there is no WMI API for your scenario. Also as you said,  MainWindowTitle process also cannot do that.

    So how about the question now? May be you should try to find is there any third-party API to do this.

    Wednesday, March 2, 2016 9:23 AM
  • Hi Linki

    If the Windows task manager is able to distinguish between 

    Apps

       * foreground apps

    Background Process

       * for background process or

       * apps in suspended state

    There has to be a way with Microsoft, unless it is so proprietary, so secret sauce, that the customers can't do that.

    I can't imagine some third party library be able to achieve that. 

    Is there someone at Microsoft you can reach to figure this out?  Appreciate that.

    Wednesday, March 2, 2016 5:33 PM
  • I can't imagine some third party library be able to achieve that. 

    Is there someone at Microsoft you can reach to figure this out?  Appreciate that.

    Hi  neondeion,

    Sorry for my late reply.

    I would suggest you suggest you to open one phone support ticket. You could contact Microsoft support for better help. It is a paid service.

    Phone support channel: https://msdn.microsoft.com/en-us/library/bb266240.aspx

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 9, 2016 8:07 AM