我想制作一个监控Windows上运行的其他程序的程序。它需要知道例如“Max Payne 2在下午4:36开放”或“Firefox在上午9:52关闭”。理想情况下,它能够区分我实际使用该程序的时间,或者我是否有alt-tabbed,或者我是否处于非活动状态。如何提取该数据?有人可以指出我正确的方向,所以我知道我需要谷歌或我需要什么样的主题拿起一本书?
答案 0 :(得分:5)
您可以执行此操作以列出正在运行的进程:
using System.Diagnostics;
.......
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine(”Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
此外,您可以使用以下属性来检索一些有趣的信息:
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)
答案 1 :(得分:0)
监控服务。将数据记录在数据库或平面文件中。monitoriing services with .NET
答案 2 :(得分:0)
我会推荐C#。你可以从@Sander Pham的例子开始。有关详细信息,请查看此文章:http://msdn.microsoft.com/en-us/library/1f3ys1f9.aspx
您必须每隔几秒左右枚举一次本地进程,这样您就可以监视哪些进程关闭并打开。要确定它们是否被使用,您可以使用一些Win32函数来确定窗口是否处于活动状态。为初学者检查一下:“GetForegroundWindow Function”。
对于C#中的示例,只需Google“c#get window focus”。
答案 3 :(得分:0)
Windows API有一个名为CreateToolhelp32Snapshot的辅助函数。