我想获得关闭和启动Windows的确切时间。
在c ++中我只使用GetTickCount64
来检索自系统启动以来经过的毫秒数(从而通过差异获得时间),但我不知道是否有一个等效的函数用于python和如果可能的话,我想避免编写c ++模块。
对于上次关机时间我不知道......也许在Windows中有某些日志?我尝试使用win32evtlog
库读取事件日志,但它只给了我一个事件并且是关于dns的。
修改: 好吧,也许我更进了一步:我使用了win32evtlog,特别是调用了ReadEvent日志,它给了我所有日志,直到它返回null。 现在,我需要一种方法来了解启动/关闭的内容..
答案 0 :(得分:1)
你应该使用pywin32库,在那里你会找到GetTickCount()函数。
http://docs.activestate.com/activepython/2.5/pywin32/win32api__GetTickCount_meth.html
希望这有帮助。
答案 1 :(得分:0)
由于这是Windows的特定问题,因此我们可以利用WMI,甚至可以使用PowerShell。要在PowerShell中解决您的问题,只需:
powershell -command "(gcim Win32_OperatingSystem).LastBootUpTime"
# Outputs: Tuesday, 9 October 2018 4:05:58 PM
要在Python中执行此操作,我们可以使用subprocess
:
from subprocess import call
call( ["powershell", "-command", "(gcim Win32_OperatingSystem).LastBootUpTime"] )
# Outputs: Tuesday, 9 October 2018 4:05:58 PM