如何解决帮助Winsys模块
| 我正在尝试使用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.\')
我有什么想念的吗?
解决方法
正如我从RegConnectRegistry文档中看到的那样:
computerName:字符串
远程计算机的名称,格式为\\\\ computername。如果没有,则本地
使用计算机。
因此,默认计算机名称值\“。\”不能在此功能中使用。似乎您正在使用的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))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。