脚本宝典收集整理的这篇文章主要介绍了Python调用管理员权限执行脚本,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1, 代码内调用管理员权限执行一个exe文件
if is_admin(): os.startfile("System-jg_new.exe") else: if sys.version_info[0] == 3: ctyPEs.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __FILE__, None, 1) os.startfile("system-jg_new.exe") else: # in python2.x ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)2, 代码内调用管理员权限执行cmd命令
if is_admin(): os.system(command) else: if sys.version_info[0] == 3: ctypes.windll.shell32.ShellExecuteW(None, "runas", "cmd.exe","/C %s"%command, None, 1)
else: # in python2.x ctypes.windll.shell32.ShellExecuteW(None, u"runas","cmd.exe","/C %s"%command, None, 1)参考博文: https://www.cnblogs.COM/leigepython/p/10532321.htML
以上是脚本宝典为你收集整理的Python调用管理员权限执行脚本全部内容,希望文章能够帮你解决Python调用管理员权限执行脚本所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。