python程序以管理员权限运行


python写的脚本有时候需要管理员权限怎么办?

直接在代码里添加权限运行

import ctypes, sys

def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False

if is_admin():
    # Code of your program here
else:
    # Re-run the program with admin rights
	ctypes.windll.shell32.ShellExecuteW(None,"runas", sys.executable, __file__, None, 1)

posted @   ElaineTiger  阅读(140)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示