📜  ctypes 以管理员身份运行 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:32.770000             🧑  作者: Mango

代码示例1
import ctypes
import sys
def admin():
    try: return ctypes.windll.shell32.IsUserAnAdmin()
    except Exception: return False
if not admin(): # If not ran as administrator, re-run it as administrator!
    ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
    sys.exit()