[python-win32] pywintypes.error: (5, 'RegSetValueEx', 'Access denied')

Tim Roberts timr at probo.com
Thu Mar 15 13:10:43 EDT 2018


Robin Kluth wrote:
>
> I use Python 2.7 on win10 and pywin32 223. I want to log messqages to
> the EventLog:
>
> dllname = os.path.dirname(__file__)
> ntl = NTEventLogHandler("Python Logging Test", dllname=dllname)
> logger = logging.getLogger("")
> logger.setLevel(logging.DEBUG)
> logger.addHandler(ntl)
>
> logger.error("This is a '%s' message", "Error")
>
> But I get:
> ...
> pywintypes.error: (5, 'RegSetValueEx', 'Zugriff verweigert')
>
> If I run the script with Admin privs, it is working.
>
> How to log as "normal" user? Am I missing something?

You can't.  If you want to log to the event log, you'll need
privileges.  Each app must register as an "event source".  Doing so
requires writing to the HKEY_LOCAL_MACHINE part of the registry, and
write requires admin privileges.

Technically speaking, it would be possible to register that source once
in an elevated process and then use it without re-registering, but the
current code does not support that.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list