I needed a simple Windows / Posix solution to check if the user has root / admin rights on the file system without installing a third-party solution. I understand that there are vulnerabilities when using environment variables, but they are consistent with my goal. Perhaps you can expand this approach for reading / writing the registry.
Python 2.6/2.7 WinXP, WinVista Wine. - , Pyton 3.x / Win7, , . .
def has_admin():
import os
if os.name == 'nt':
try:
temp = os.listdir(os.sep.join([os.environ.get('SystemRoot','C:\\windows'),'temp']))
except:
return (os.environ['USERNAME'],False)
else:
return (os.environ['USERNAME'],True)
else:
if 'SUDO_USER' in os.environ and os.geteuid() == 0:
return (os.environ['SUDO_USER'],True)
else:
return (os.environ['USERNAME'],False)