Skip to content

Commit a2cf984

Browse files
[3.10] gh-92007: Handle elevation errors in NTEventLogHandler more grace… (GH-96322) (GH-96338)
1 parent 91b6ca4 commit a2cf984

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
@@ -1098,7 +1098,16 @@ def __init__(self, appname, dllname=None, logtype="Application"):
10981098
dllname = os.path.join(dllname[0], r'win32service.pyd')
10991099
self.dllname = dllname
11001100
self.logtype = logtype
1101-
self._welu.AddSourceToRegistry(appname, dllname, logtype)
1101+
# Administrative privileges are required to add a source to the registry.
1102+
# This may not be available for a user that just wants to add to an
1103+
# existing source - handle this specific case.
1104+
try:
1105+
self._welu.AddSourceToRegistry(appname, dllname, logtype)
1106+
except Exception as e:
1107+
# This will probably be a pywintypes.error. Only raise if it's not
1108+
# an "access denied" error, else let it pass
1109+
if getattr(e, 'winerror', None) != 5: # not access denied
1110+
raise
11021111
self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE
11031112
self.typemap = {
11041113
logging.DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,

0 commit comments

Comments
 (0)