Answer the question
In order to leave comments, you need to log in
How to know if a script is running as administrator?
You need to find out that the script is running on behalf of the administrator. And if not, then close the program and politely ask to run it from the admin
Answer the question
In order to leave comments, you need to log in
import ctypes, os
try:
is_admin = os.getuid() == 0
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
print is_admin
whoami
There is os.getuid() which "Returns the current process's user id.". But how do I find out any given user's id?
The root user has id 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question