Cross-platform way to check admin rights in a Python script under Windows?

grigoryvp picture grigoryvp · Jun 22, 2009 · Viewed 15.2k times · Source

Is there any cross-platform way to check that my Python script is executed with admin rights? Unfortunately, os.getuid() is UNIX-only and is not available under Windows.

Answer

grigoryvp picture grigoryvp · Jun 22, 2009
import ctypes, os
try:
 is_admin = os.getuid() == 0
except AttributeError:
 is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0

print is_admin