以编程方式获取上次启动/关闭时间 [英] Programmatically get last boot/shutdown time
问题描述
我想获取关闭和启动Windows的确切时间.
在c ++中,我只使用GetTickCount64
即可检索自系统启动以来经过的毫秒数(从而通过时间来获取时间),但是我不知道python是否具有等效的功能,如果可能的话,我想避免编写一个c ++模块.
I'd like to get the exact time when windows was shut down and booted.
In c++ I'd simply use GetTickCount64
which retrieves the number of milliseconds that have elapsed since the system was started (thus obtaining the time by difference), but I don't know if there is an equivalent function for python and, if possible, I'd like to avoid to write a c++ module.
对于上次关闭时间,我不知道...也许在Windows中某处有一些日志?我尝试使用win32evtlog
库读取事件日志,但是它只给我一个事件,并且是关于dns的.
For last shutdown time I have no idea...maybe there is some log somewhere in windows? I tried to read the event log using win32evtlog
library, but it gives me just an event and is about the dns..
好的,也许我可以走得更远:我使用了win32evtlog,尤其是多次调用ReadEvent日志,它将为我提供所有日志,直到返回null. 现在,我需要一种方法来了解有关启动/关闭的ID.
edit: Ok, maybe I got a step further: I used win32evtlog, in particular calling ReadEvent log more times it gives me all logs till it returns null. Now, I need a way to understand what ids are about boot/shutdown..
推荐答案
您应该使用pywin32库,然后在其中找到GetTickCount()函数.
You should use the pywin32 library, and there you'll find the GetTickCount() function.
http://docs.activestate.com/activepython/2.5/pywin32/win32api__GetTickCount_meth.html
希望这会有所帮助.
这篇关于以编程方式获取上次启动/关闭时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!