none
How to find the Current Running Application using c#.net?

    Question

  • Hi folks!

    How can I find the application which is currently running application using C#?

    Scenario: I m developing C# WinForms application. If MS Excel, Explorer, AutoCAD, Visual Studio and some other applications are opened and the user is currently working in Visual Studio, then in the timer, I want to the messagebox to show the application name as Visual studio. not as Excel or some other application name not even my application name.

    Problem: I have used Process.GetCurrentProcess() method to get it, but it each time returns my application name even if I am working in other application. 

    Hope I am clear with the problem.. 

    Thank you all for the answers and support in advance..

    Regards,
    Vi

    Vidyadhar - V the destiny
    Monday, January 18, 2010 12:23 PM

Answers

All replies


  • You should use

    Process[] currentProcesses = Process.GetProcesses();

    to get current processes. And then search that array if either of those applications are running.


    Thanks

    Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
    My BlogMy Facebook
    • Marked as answer by Jing0Moderator Sunday, January 24, 2010 1:28 PM
    • Unmarked as answer by V The Destiny Thursday, January 28, 2010 12:02 PM
    Monday, January 18, 2010 1:08 PM
  • Hi,

    you should use GetForegroundWindow(). For an example, take a look here:
    http://www.csharphelp.com/2006/08/get-current-window-handle-and-caption-with-windows-api-in-c/


    Marcel
    • Proposed as answer by Mike_999 Tuesday, January 19, 2010 11:43 AM
    • Marked as answer by Jing0Moderator Sunday, January 24, 2010 1:28 PM
    Monday, January 18, 2010 1:34 PM
  • Hi Omie and Marcel,

    Thank you for the quick response.. 

    Omie, I dont want to get the list of processes that are running in my machine, I want which one of those process array is currently active, I mean which application the User is currently working on..

    Marcel, it seems a relevant suggestion to me, I will try with ur suggestion.. 

    Is there any other methods guys?



    Vidyadhar - V the destiny
    Monday, January 18, 2010 2:13 PM
    • Proposed as answer by Mike_999 Tuesday, January 19, 2010 11:43 AM
    • Marked as answer by Jing0Moderator Sunday, January 24, 2010 1:28 PM
    Tuesday, January 19, 2010 11:06 AM
  • Hi,

     

    I think their replays are really helpful. Did this problem resolved? If anything unclear, please feel free to tell us.

     

    Best regards,

    Ling Wang


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, January 22, 2010 4:11 AM