A
A
arynyklas2020-01-06 12:40:38
Python
arynyklas, 2020-01-06 12:40:38

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

2 answer(s)
D
Dimonchik, 2020-01-06
@arynyklas

import ctypes, os
try:
 is_admin = os.getuid() == 0
except AttributeError:
 is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0

print is_admin

V
Vladimir Korotenko, 2020-01-06
@firedragon

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 question

Ask a Question

731 491 924 answers to any question