So, let's start with the base problem;
Program writes a file as user of elevated rights.
Later: Same program tries to overwrite the file without elevated rights.
In Windows this clashes with:
PermissionError: [Errno 13] Permission denied: '
filepath
'
CHMOD
doesn't work under
windows anyway.everybody write
"
permission, then this would not be a problem.read-only
flag but it doesn't solve the ownership issue.So I tried win32security However, the call to LookupAccountName is locale dependent:
>>> win32security.LookupAccountName(None, "Everyone")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pywintypes.error: (1332, 'LookupAccountName', 'Zuordnungen von Kontennamen und Sicherheitskennungen wurden nicht durchgeführt.')
>>> win32security.LookupAccountName(None, "Jeder")
(<PySID object at 0x00000184AA586560>, '', 5)
And therefore not portable. I also found no way of manually creating the "Everyone
" SID, the docs are rather minimal in that respect. But I might also be following the wrong rabbit hole.
Edit: If it matters, in this particular case at least, all relevant files are under "%programdata%/programname/*" in windows.
This problem went away with one of the windows updates within the 1903 timeframe. Some additional digging seems to suggest this was a bug in windows IF that system is part of a domain and ownership would fall into a domain user.