【问题标题】:Python equivalent of PowerShell Get-EventLogPython 等效于 PowerShell Get-EventLog
【发布时间】:2014-09-07 20:40:18
【问题描述】:
在 PowerShell 中,您可以运行此命令来列出服务器上所有不同的事件日志文件夹:
Get-EventLog -list
有没有办法在 Python 中做到这一点?我看过很多关于如何从特定文件夹(例如使用win32evtlog)获取日志的帖子,但没有看到如何检索所有事件日志文件夹的列表。我正在运行 Windows Server 2008。
【问题讨论】:
标签:
python
windows
powershell
event-log
【解决方案1】:
想通了。
>>> import win32evtlog
>>> x = win32evtlog.EvtOpenChannelEnum()
>>> win32evtlog.EvtNextChannelPath(x)
u'Application'
>>> win32evtlog.EvtNextChannelPath(x)
u'HardwareEvents'
>>> win32evtlog.EvtNextChannelPath(x)
u'Internet Explorer'
>>>