📌  相关文章
📜  以管理员身份运行文件 python 代码示例

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

代码示例1
# Run file as administrator on Windows 7, 8, 10
# Tested for Python 3.8.5
import os

def RunAsAdmin(path_to_file,*args):
    os.system(r'Powershell -Command "Start-Process "'+path_to_file+'"'+ # CMD running Powershell
                ' -ArgumentList @('+str(args)[1:-1]+')'+ # Arguments. [1:-1] to remove brackets
                ' -Verb RunAs"' # Run file as administrator
    )

RunAsAdmin('cmd.exe','arg1','arg2')