Get the current active process from winform

T

Tal Shachar

Hello,
I'm writing a windows application, that monitors running
processes/applications on my machine. One of the requirements is to identify
the current active process/application.
I tried to use the System.Diagnostics.Process.GetCurrentProcess() method,
but the thing is that it always returns my application's process.
Is there another way to get the current active process? What am I missing
here?

Appreciate all the help I can get.
Thanks in advance,
- Tal.
 
M

Michael Nemtsev

Hello Tal,

What does "active" process mean? That is user works with or ...?!

TS> Hello,
TS> I'm writing a windows application, that monitors running
TS> processes/applications on my machine. One of the requirements is to
TS> identify
TS> the current active process/application.
TS> I tried to use the System.Diagnostics.Process.GetCurrentProcess()
TS> method,
TS> but the thing is that it always returns my application's process.
TS> Is there another way to get the current active process? What am I
TS> missing
TS> here?
TS> Appreciate all the help I can get.
TS> Thanks in advance,
TS> - Tal.
---
WBR, Michael Nemtsev [C# MVP] blog: http://spaces.live.com/laflour
team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
T

Tal Shachar

Hi Michael,
Active Process means the current application/process that the user is
currently working on. To be more clear - the current application which is
selected in the Task Bar (if it is shown in the task bar).
Thanks for your reply,

- Tal.
 
G

Guest

Hi Tal,

Maybe you can use the Win32 API GetForegroundWindow to retrieve a handle to
the foreground window and then compare to
System.Diagnostics.Process.MainWindowHandle to find the process that owns the
window.

http://www.pinvoke.net/default.aspx/user32/GetForegroundWindow.html

HTH, Jakob.
--
http://www.dotninjas.dk



Tal Shachar said:
Hi Michael,
Active Process means the current application/process that the user is
currently working on. To be more clear - the current application which is
selected in the Task Bar (if it is shown in the task bar).
Thanks for your reply,

- Tal.


Michael Nemtsev said:
Hello Tal,

What does "active" process mean? That is user works with or ...?!

TS> Hello,
TS> I'm writing a windows application, that monitors running
TS> processes/applications on my machine. One of the requirements is to
TS> identify
TS> the current active process/application.
TS> I tried to use the System.Diagnostics.Process.GetCurrentProcess()
TS> method,
TS> but the thing is that it always returns my application's process.
TS> Is there another way to get the current active process? What am I
TS> missing
TS> here?
TS> Appreciate all the help I can get.
TS> Thanks in advance,
TS> - Tal.
---
WBR, Michael Nemtsev [C# MVP] blog: http://spaces.live.com/laflour
team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
T

Tal Shachar

Hi Jacob,
Thanks for your suggestion (and for the VERY helpful url).
I'll sure try it.
- Tal.


Jakob Christensen said:
Hi Tal,

Maybe you can use the Win32 API GetForegroundWindow to retrieve a handle
to
the foreground window and then compare to
System.Diagnostics.Process.MainWindowHandle to find the process that owns
the
window.

http://www.pinvoke.net/default.aspx/user32/GetForegroundWindow.html

HTH, Jakob.
--
http://www.dotninjas.dk



Tal Shachar said:
Hi Michael,
Active Process means the current application/process that the user is
currently working on. To be more clear - the current application which is
selected in the Task Bar (if it is shown in the task bar).
Thanks for your reply,

- Tal.


Michael Nemtsev said:
Hello Tal,

What does "active" process mean? That is user works with or ...?!

TS> Hello,
TS> I'm writing a windows application, that monitors running
TS> processes/applications on my machine. One of the requirements is to
TS> identify
TS> the current active process/application.
TS> I tried to use the System.Diagnostics.Process.GetCurrentProcess()
TS> method,
TS> but the thing is that it always returns my application's process.
TS> Is there another way to get the current active process? What am I
TS> missing
TS> here?
TS> Appreciate all the help I can get.
TS> Thanks in advance,
TS> - Tal.
---
WBR, Michael Nemtsev [C# MVP] blog: http://spaces.live.com/laflour
team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and
we
miss it, but that it is too low and we reach it" (c) Michelangelo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top