Winsys模块帮助

0 投票
1 回答
527 浏览
提问于 2025-04-16 19:17

我正在尝试使用WinSys模块来获取我系统(Windows)的事件日志。但是我不知道为什么下面的代码无法运行:

from winsys import event_logs
print len (event_logs.event_log ("Application"))

或者

for logs in event_logs.event_logs(computer='.'):
    print logs

这些会出现错误

Traceback (most recent call last):
  File "Q:\8th sem\python\untitled1.py", line 10, in <module>
    event_logs.event_log("Application")
  File "C:\Python26\lib\site-packages\winsys\event_logs.py", line 376, in event_log
    return EventLog (computer, log_name)
  File "C:\Python26\lib\site-packages\winsys\event_logs.py", line 119, in __init__
    key = registry.registry (self.REG_ROOT % self.computer).get_key (self.name)
  File "C:\Python26\lib\site-packages\winsys\registry.py", line 503, in registry
    return Registry.from_string (root, access=access, accept_value=accept_value)
  File "C:\Python26\lib\site-packages\winsys\registry.py", line 485, in from_string
    hKey, moniker, value = cls._from_string (string, access, accept_value)
  File "C:\Python26\lib\site-packages\winsys\registry.py", line 469, in _from_string
    hRoot = wrapped (win32api.RegConnectRegistry, computer, root)
  File "C:\Python26\lib\site-packages\winsys\exc.py", line 44, in _wrapped
    raise exception (errno, errctx, errmsg)
winsys.registry.x_registry: (53, 'RegConnectRegistry', 'The network path was not found.')

我是不是漏掉了什么?

1 个回答

0

根据RegConnectRegistry的文档,我可以看到以下内容:这里

computerName : 字符串 远程计算机的名称,格式为\\计算机名称。如果是None,则使用本地计算机。

所以,默认的计算机名称值“.”在这个函数中是不能使用的。看起来你使用的Winsys版本有个小问题。在我本地的Winsys版本0.5.2(从PYPI下载的)中,这个问题似乎已经修复了。

你可以通过以下代码来解决这个问题:

import win32api
from winsys import event_logs
moniker = "\\\\%s\\Application" % win32api.GetComputerName()
print len(event_logs.event_log(moniker))

撰写回答