【问题标题】:How to answer admin password prompt in os in python如何在python的操作系统中回答管理员密码提示
【发布时间】:2016-05-07 07:54:51
【问题描述】:

我最近找到了一种方法,可以在 Windows 10 的 cmd 中以管理员身份运行任何程序:

runas /user:"John" "cmd /c regedit"

我想在 python 中重新创建它:

os.system('runas /user:"John" "cmd /c regedit"')

问题是我需要写下密码,而操作系统似乎跳过了密码。如何向此代码添加密码信息?欢迎任何其他实现相同目标的更好选择。

【问题讨论】:

    标签: python cmd operating-system runas


    【解决方案1】:

    您可能应该使用 pexpect 之类的东西而不是 os.system https://pexpect.readthedocs.io/en/stable/

    process = pexpect.spawn('runas /user:"John" "cmd /c regedit"')
    process.expect("Password:") // or whatever else you are prompted with
    process.sendline("*******") // your password
    

    【讨论】:

    • 不起作用。 Python给我错误:AttributeError:模块'pexpect'没有属性'spawn'
    猜你喜欢
    • 2020-02-01
    • 2012-05-29
    • 2019-02-17
    • 1970-01-01
    • 2015-02-18
    • 2021-10-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    相关资源
    最近更新 更多