我怎么知道Windows程序运行了多长时间 [英] How do I know how long a windows program has been running

查看:254
本文介绍了我怎么知道Windows程序运行了多长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我需要知道Windows程序运行了多长时间,以及它在没有用户与之交互的情况下运行了多长时间。 />


如果用户不使用它,则自动关闭程序。



谢谢。 />


我尝试了什么:



Hello,

I need to know how long a Windows program has been running, and how long has it been running without the user interacting with it.

The point is to automatically close the program if the user is not using it.

Thanks.

What I have tried:

I searched for a Windows API function that gaves me that information, but I didn't find any.

推荐答案

获取运行时间Windows应用程序,您可以使用 GetProcessTimes函数(Windows) [ ^ ]传递流程句柄( GetCurrentProcess功能(Windo ws) [ ^ ])。要获得运行时间,请从当前时间中减去 lpCreationTime



使用C / C ++,您也可以使用时钟 [ ^ ]功能。



要知道最后一次您必须获得的用户交互并将时间存储在每个用户输入中。如何实现这取决于您的应用程序的类型。一种选择是使用 SetWindowsHookEx函数挂钩键盘和鼠标事件(Windows) [ ^ ]。另请参见 Hooks Overview(Windows) [< a href =https://msdn.microsoft.com/en-us/library/windows/desktop/ms644959(v=vs.85).aspx\"target =_ blanktitle =New Window> ^ ]。
To get the run time of a Windows application you can use the GetProcessTimes function (Windows)[^] passing the process handle (GetCurrentProcess function (Windows)[^]). To get the run time subtract the lpCreationTime from the current time.

With C/C++ you can also use the clock[^] function.

To know the last time of user interaction you have to get and store the time at each user input. How to implement this depends on the kind of your application. One option is to hook keyboard and mouse events using the SetWindowsHookEx function (Windows)[^]. See also Hooks Overview (Windows)[^].


我从Process API开始 - 有关于返回的各种'时间'开始时间的信息: - 进程类(System.Diagnostics) [ ^ ]



查看StartTime,TotalProcessorTime,UserProcessorTime并查看是否满足您的需求
I'd start with the Process API - there is information on various 'times' start time etc returned :- Process Class (System.Diagnostics)[^]

Look at StartTime, TotalProcessorTime, UserProcessorTime and see if any/all of those meet your needs


感谢您的回答,Jochen和Garth。



该计划我需要控制的不是我的申请,而是一个商业计划。我还找到了GetProcessTimes,但是这个函数没有返回我需要的时间。



两者都没有找到Process Class的解决方案。



解决方案可以是使用以下程序之一:



空闲软件更紧密 - 自动关闭程序并发许可证 [ ^ ]



自动关闭空闲程序,会计,财务和数据库应用程序 [ ^ ]



尝试自己做的一个解决方案是连续检查程序是否空闲,并在检测到空闲时使用计时器进行控制。但是,据我检查,如果Windows程序空闲,两个解决方案都不会返回。
Thanks for your answers, Jochen and Garth.

The program that I need to control is not my application, it's a comercial program. I yet found the GetProcessTimes, but this function does not return the time that I need.

Neither found the solution with the Process Class.

The solution can be to use one of these programs:

Idle Software Closer - Automatically Close Programs Concurrent License[^]

Auto Close Idle Programs, Accounting, Financial, and Database applications[^]

One solution to try to do it myself can be to check continuously if the program is idle or not, and control with a timer when I detect that it is idle. But, as far as I checked, none of both solutions returns if the Windows program is idle or not.


这篇关于我怎么知道Windows程序运行了多长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆