Execute command as admin using subprocess

后端 未结 1 344
一生所求
一生所求 2020-12-22 13:03

I want to execute installation command as an admin via subprocess. How can I run command as an admin? Here what I have so far:

import subprocess

subprocess.         


        
相关标签:
1条回答
  • 2020-12-22 13:24

    Try:

    import os
    subprocess
    os.chdir("C:\\Users\\user\\")
    
    cmd= subprocess.Popen(["runas", "/noprofile", "/user:Administrator", "|", "echo", "Y", "|", "choco", "install", "dropbox"],stdin=sp.PIPE)
    cmd.stdin.write('password')
    cmd.communicate()
    
    0 讨论(0)
提交回复
热议问题