python运行在windows检查是否有管理员权限
可以使用以下代码来检查Python是否有管理员权限:
import ctypes
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
print("Python has administrator privileges.")
else:
print("Python does not have administrator privileges.")
该函数使用 ctypes 库中的 windll.shell32.IsUserAnAdmin() 函数来检查当前用户是否是管理员。如果函数返回 True,则 Python 具有管理员权限。否则,Python 不具有管理员权限。
原文地址: https://www.cveoy.top/t/topic/frr3 著作权归作者所有。请勿转载和采集!