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?
views:
80answers:
4You 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)
Monitor the services. Log the data in a database or in flat files.monitoriing services with .NET
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".
The Windows API has a helper function called CreateToolhelp32Snapshot.