How do you know that the script runs as administrator?

Need to know what script is running as administrator. And if not then terminate the program and politely ask to run as admin
April 4th 20 at 00:55
2 answers
April 4th 20 at 00:57
Solution
import ctypes, os
try:
 is_admin = os.getuid() == 0
except AttributeError:
 is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0

print is_admin
April 4th 20 at 00:59
whoami

There is os.getuid() which "Returns the current process''s user id.". But how do I find out any given user's id?


Ruth has user id 0

Find more questions by tags PythonSystem administration