Python 等价于 PowerShell 的 Get-EventLog
在PowerShell中,你可以运行这个命令来列出服务器上所有不同的事件日志文件夹:
Get-EventLog -list
有没有办法用Python做到这一点?我看到很多帖子讲的是如何从特定的文件夹获取日志(比如使用win32evtlog
),但没有看到如何获取所有事件日志文件夹的列表。我正在使用Windows Server 2008。
1 个回答
1
我搞明白了。
>>> import win32evtlog
>>> x = win32evtlog.EvtOpenChannelEnum()
>>> win32evtlog.EvtNextChannelPath(x)
u'Application'
>>> win32evtlog.EvtNextChannelPath(x)
u'HardwareEvents'
>>> win32evtlog.EvtNextChannelPath(x)
u'Internet Explorer'
>>>