我如何获得PC电源关闭的时间? [英] How i can get the time of PC Power OFF ?

查看:98
本文介绍了我如何获得PC电源关闭的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立考勤系统,所以当用户单击登录和注销"按钮时,我将使用登录时间和注销时间.

但是我还有另一种情况,如果PC断电,这意味着我将存储登录时间,而注销时间将不会设置,因此我想将断电时间视为注销时间,我该如何获取这次.

I am Making attendance System so I''m take the time of log in and the time of log out when user click on Login and Logout button .

but i have another scenario if power off on PC this mean i will store the time of log in and the time of log out will not set so i want to consider the time of power off to be the time of log out how i can get this time.

推荐答案

您可能需要实现
You will probably need to implement OnShutdown()[^] method, or similar.


创建Windows服务并将所需的信息记录到服务器计算机上的外部数据库中.

简单Windows服务示例 [
Create a windows service and log the information you require to an external database on a server machine.

Simple Windows Service Sample[^]


如果我正确理解了您的问题,我想您希望跟踪突然断电的时间,系统上会发生硬关闭,因此系统事件日志中不会有任何条目.我唯一的建议是,您使用Mehdi的建议来创建一个简单的服务,该服务每分钟左右将内容写入外部数据库,如果发生此类事件,您将在一分钟之内准确无误.
If I understand your question correctly, I think you want to be able to trace the time at which a sudden power loss, hard shut down occurs on the system whereby there won''t be an entry in the system event logs. The only suggestion I would have is that you use Mehdi''s suggestion to create a simple service that writes something every minute or so to an external database by which you will then be accurate to within a minute if such an event occurs.


这篇关于我如何获得PC电源关闭的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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