Windows下使用Python脚本检查管理员权限的跨平台方法? [英] Cross-platform way to check admin rights in a Python script under Windows?
本文介绍了Windows下使用Python脚本检查管理员权限的跨平台方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何跨平台的方法来检查我的Python脚本是否具有管理员权限?不幸的是,os.getuid()
仅适用于UNIX,在Windows下不可用.
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.
推荐答案
import ctypes, os
try:
is_admin = os.getuid() == 0
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
print is_admin
这篇关于Windows下使用Python脚本检查管理员权限的跨平台方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文