进程计时

发布于 2024-08-14 11:41:44 字数 81 浏览 1 评论 0原文

如何计算当日同组的每个应用程序Win(进程)的总执行时间。

例如: 进程 - notepad.exe - 今天 10 分钟(总共)

How to calculate the total execution time of each application Win (process) with the group on day.

For example:
the process - notepad.exe - 10 minutes today (in total)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话难免假 2024-08-21 11:41:44

我将使用针对 Win32_Process 的 WMI 查询并根据 MSDN 是进程开始执行的日期(和时间)。

Magenta Systems 提供了一个很好的 Delphi 库。该库包含几个示例来帮助您入门。

这只跟踪当前正在运行的进程。如果您想要跟踪曾经运行过但不再运行的进程,那么您将需要挂接到窗口,以便在每次应用程序启动时收到通知。其中一个示例是使用 CBT 挂钩(基于计算机的培训,但也用于其他用途),它允许您在每次创建窗口时收到通知。如果您使用窗口句柄来查找父进程,则可以使用它来自己跟踪父进程运行了多长时间。

I would use a WMI query against Win32_Process and retrieve the CreationDate value which according to MSDN is the date (and time) a process began executing.

A good library for Delphi is available from Magenta Systems. This library includes several examples to help you get started.

This only tracks currently running processes. If your wanting to track processes which were run once but are no longer running, then you will want to hook into windows so you are notified at each application launch. One example of this would be to use the CBT hooks (computer based training, but its used for other things also) which allow you to get notified every time a window is created. If you use the window handle to then find the parent process, you can then use this to track for yourself how long the parent process is running.

唯憾梦倾城 2024-08-21 11:41:44

Win32 函数 GetProcessTimes 是获取创建时间和一天中所用 CPU 时间的另一种方法。对于执行时间,我假设您指的是 cpu 时间而不是挂钟时间。

这里是描述如何在 Delphi 中使用 GetProcessTimes 的博客文章的链接

这是比使用 WMI 更“直接”的方法,但是 WMI 还有其他优点,例如能够通过网络查询其他计算机。

正如 skamradt 还建议的那样,该应用程序需要连续运行以跟踪所有启动和停止进程。我知道的唯一方法获取启动和停止应用程序的事件是使用 WMI 事件。 有关更多信息,请参阅此问题以及这个关于脚本编写的 Technet 博客

执行此操作的步骤是

  1. 枚举所有正在运行的进程 此问题涵盖
  2. ,然后为每个进程调用 GetProcessTimes 如此处所述

The Win32 function GetProcessTimes is an alternative way of getting hold of the creation time and CPU time spent during the day. With execution time I assume you mean cpu time rather than wall clock time.

Here is a link to a blog post describing how to use GetProcessTimes in Delphi.

This is a more "direct" approach than using WMI, however WMI has other advantages such as being able to query other machines over the network.

As skamradt also suggests, this application needs to run continuously to track all starting and stopping processes.The only way I know of to get events on starting and stopping applications is to use WMI events. See this question for some more info on that as well as this Technet blog on scripting

The steps to do this would be to

  1. enumerate all running processes covered by this question
  2. and then call GetProcessTimes for each process as described here.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文