Take the 2-minute tour ×

I want to make a program that monitors the other programs running on Windows. It needs to know for instance "Max Payne 2 opened at 4:36pm" or "Firefox closed at 9:52 am." Ideally, it would be able to tell the difference between when I'm actually using the program, or if I have alt-tabbed out of it or if I'm inactive. How do I extract that data? Could someone please just point me in the right direction so I know what phrase I need to google or what topic I need to pick up a book on?

share|improve this question
add comment

4 Answers

up vote 7 down vote accepted

You can do this in order to list the running processes:

  using System.Diagnostics;


  Process[] processlist = Process.GetProcesses();

     foreach(Process theprocess in processlist){
     Console.WriteLine(”Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);

Furthermore, you may use the following properties to retrieve some interesting info:

 theprocess.StartTime (Shows the time the process started)
 theprocess.TotalProcessorTime (Shows the amount of CPU time the process has taken)
 theprocess.Threads ( gives access to the collection of threads in the process)
share|improve this answer
That's C#, right? I googled "System.Diagnostics" to figure out the language and the result seems to show it's C#, but I would appreciate a confirmation. I'm a programming beginner in case it wasn't obvious or you didn't notice it in the tag. –  lala Jun 22 '10 at 1:34
Yes, System.Diagnostics, C# –  Sander Pham Jun 22 '10 at 1:41
add comment

The Windows API has a helper function called CreateToolhelp32Snapshot.

share|improve this answer
please don't post old links. There's nothing in the question that suggests the OP needs the "VS.85" version of the information. –  John Saunders Jun 22 '10 at 1:22
@John, thanks for updating the link, but please skip the lecture next time. You can blame Google for that one. –  Marcus Adams Jun 22 '10 at 14:13
Actually, I blame you. You apparently know that MSDN includes versions in the links. Next time, look before you post and the problem won't arise again. Besides, I said "please". –  John Saunders Jun 22 '10 at 14:30
@John, I said please too, and I didn't know about versions until now. You assume the worst. Next time, try something like, "Marcus, I updated your link. In case you weren't aware, MSDN has versions in their links." –  Marcus Adams Jun 22 '10 at 14:39
I assumed the usual. Most people know about the versions. BTW, the issue with the old links is that, as you follow links from one old page, you get more old links. Someone who thought he was looking at current information could wind up with old information about something totally unrelated, just by following an old link. –  John Saunders Jun 22 '10 at 21:04
add comment

I would recommend C#. You can start with @Sander Pham's example. Check out this article for more information: http://msdn.microsoft.com/en-us/library/1f3ys1f9.aspx

You would have to enumerate local processes every few seconds or so, so you can monitor when which of them close and open. To figure out if they are being used, you can use some Win32 functions to determine if the windows are active or not. Check this out for starters: "GetForegroundWindow Function".

For examples in C#, just Google "c# get window focused".

share|improve this answer
he didn't ask for a language recommendation. Also, please don't post old links. –  John Saunders Jun 22 '10 at 1:17
The language recommendation was relevant to the question, so I appreciate it. Also, I'm not a he. –  lala Jun 22 '10 at 1:32
@John Saunders I appreciate your removing the bad links, but because she didn't specify what language she was using, I thought I would recommend one –  Chris Laplante Jun 22 '10 at 13:46
add comment

Monitor the services. Log the data in a database or in flat files.monitoriing services with .NET

share|improve this answer
add comment

Your Answer


