Home All Groups Group Topic Archive Search About

Get the current active process from winform

Author
3 Feb 2007 6:41 PM
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.

Author
3 Feb 2007 7:27 PM
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
Author
5 Feb 2007 7:02 AM
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.


Show quote
"Michael Nemtsev" <nemt***@msn.com> wrote in message
news:a279a63a3db0bf8c915f998e17075@msnews.microsoft.com...
> 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
>
>
Author
5 Feb 2007 9:00 AM
Jakob Christensen
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.
Show quote
"Tal Shachar" wrote:

> 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" <nemt***@msn.com> wrote in message
> news:a279a63a3db0bf8c915f998e17075@msnews.microsoft.com...
> > 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
> >
> >
>
>
>
Author
5 Feb 2007 9:55 AM
Tal Shachar
Hi Jacob,
Thanks for your suggestion (and for the VERY helpful url).
I'll sure try it.
  - Tal.


Show quote
"Jakob Christensen" <JakobChristen***@discussions.microsoft.com> wrote in
message news:44C0A913-6C4E-4BBC-998E-F34A2FAB0143@microsoft.com...
> 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" wrote:
>
>> 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" <nemt***@msn.com> wrote in message
>> news:a279a63a3db0bf8c915f998e17075@msnews.microsoft.com...
>> > 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
>> >
>> >
>>
>>
>>

AddThis Social Bookmark Button