如何使用管理员在 Win 7 上使用 Python 执行 cmd 命令 [英] How to executes cmd command using Python on Win 7 with admin

查看:40
本文介绍了如何使用管理员在 Win 7 上使用 Python 执行 cmd 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,我想执行cmd命令:

in python, i want to executes cmd command:

os.system("netsh interface set interface \"Local Area Connection\" disable")

断开互联网网络.但是,使用我的帐户,它报告,接口名称未注册路由器.我认为,我需要以管理员身份执行 os.system .但我不知道如何以管理员身份使用它!所以,你能帮我吗!谢谢.

to disconnect internet network. But, with my account, it report, interface name not register router. I think that, i need to executes os.system as admin. But i don't know how to use it as admin! So, can you help me! Thank.

推荐答案

要在 Windows 上以管理员身份运行命令,您可以使用 Windows runas 命令(我现在无法访问 Windows 机器,但也许......);

To run command as admin on Windows, ou can use Windows runas command (I don't have access to a Windows machine right now, but perhaps..);

import subprocess
subprocess.call(['runas', '/user:Administrator', 'Your command'])

这篇关于如何使用管理员在 Win 7 上使用 Python 执行 cmd 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆