Python WMI名字对象问题

2024-05-23 16:18:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法使用WMI查询日志“安全性”。其他的原木也可以。我用的是:

import wmi
c = wmi.GetObject(r"winmgmts:{impersonationLevel=delegate,(Security)}!\\.\root\cimv2")
for i in c.ExecQuery("SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Security'"):
    print i

它返回空结果,并在安全日志中创建reacord“audit failed”。如前所述,我可以查询所有其他日志,但不能查询特定的日志。 所以我想问题出在

c = wmi.GetObject(here is a problem)


Tags: inimportforrootwmiselectsecurity原木
1条回答
网友
1楼 · 发布于 2024-05-23 16:18:24

你考虑过走win32evtlog的路吗?这是我过去用过的方法的一部分,看起来效果很好。。。在

import win32evtlog

outfile = open('NTLog.log', 'w')
server = 'SERVER_Name'
logtype = 'Security'
hand = win32evtlog.OpenEventLog(server, logtype)
flags = win32evtlog.EVENTLOG_BACKWARDS_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ
total = win32evtlog.GetNumberOfEventLogRecords(hand)
count = 0
while count != total:
    events = win32evtlog.ReadEventLog(hand, flags,0)
    if events:
        for event in events:
            data = event.StringInserts
            if data:
                outfile.write(data[0])

这并不是一个完整的实现,但希望它能让您回到正轨!在

相关问题 更多 >