我正在尝试使用 Pythons (2.7) 将数据写入 Windows 7 上的系统日志logging.handlers.NTEventLogHandler
。这不起作用,因为显然有一些注册表访问被拒绝。该软件将在没有任何特殊访问权限的情况下运行。有什么办法可以使这项工作?
这是我得到的例外:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> from logging import handlers
>>> syslog = handlers.NTEventLogHandler("Something")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\logging\handlers.py", line 917, in __init__
self._welu.AddSourceToRegistry(appname, dllname, logtype)
File "c:\Python27\lib\site-packages\win32\lib\win32evtlogutil.py", line 35, in
AddSourceToRegistry
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (eventLogType, app
Name))
pywintypes.error: (5, 'RegCreateKey', 'Access is denied.')