How to get process id of active task?

  • Thread starter Thread starter Holger Kasten
  • Start date Start date
H

Holger Kasten

How to get process id of active task?

With active task I mean the task that is being used by the user...
 
Holger,

Include the System.Diagnostics namespace into your file and use
the following code to get what you want:

Process p = Process.GetCurrentProcess();
int pid = p.Id;

HTH,

//Andreas
 
Unfortunately this just gives me my own pid.
I want to know the pid of the application that the user interacts with.
 
Holger,

I was under the impression that you ment the application (your
application)
which was being used. Using the Process class you can get a hold of other
processes than your own. You do not provide any information about the
application which is being interacted with (like, did you develop it
yourself etc)
so I can only provide you with some general informtion. The process class
has
three other static methods which may help you

- GetProcessById
- GetPriocesses (You could enumerate them will you found the right exe
etc)
- GetProcessesByName

Perhaps you could provide us with a bit more information on what you are
trying
to do?

HTH,

//Andreas
 
Andreas,

I want to do an app that logs the different applicationsa that have been
used by the user.
This should be the first step. So if the user first uses the Explorer, than
Word, than Corel Draw.
I would like to have log that shows the exe file name of each aplication and
the order they have been used.

eg. explorer.exe
word.exe
corel.exe

The second step is to know how long the user used each application.

I do not want to know when the user started the apps. I just want to know
when the user
uses the apps.

Any idea how to do this?
 
Back
Top