Skip to content

Commit 013e659

Browse files
authored
gh-92007: Handle elevation errors in NTEventLogHandler more grace… (GH-96322)
1 parent 0ace820 commit 013e659

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Lib/logging/handlers.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,16 @@ def __init__(self, appname, dllname=None, logtype="Application"):
11111111
dllname = os.path.join(dllname[0], r'win32service.pyd')
11121112
self.dllname = dllname
11131113
self.logtype = logtype
1114-
self._welu.AddSourceToRegistry(appname, dllname, logtype)
1114+
# Administrative privileges are required to add a source to the registry.
1115+
# This may not be available for a user that just wants to add to an
1116+
# existing source - handle this specific case.
1117+
try:
1118+
self._welu.AddSourceToRegistry(appname, dllname, logtype)
1119+
except Exception as e:
1120+
# This will probably be a pywintypes.error. Only raise if it's not
1121+
# an "access denied" error, else let it pass
1122+
if getattr(e, 'winerror', None) != 5: # not access denied
1123+
raise
11151124
self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE
11161125
self.typemap = {
11171126
logging.DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,

0 commit comments

Comments
 (0)