在python中,我要执行cmd命令:os.system(netsh interface set interface \Local Area Connection\ disable)断开互联网连接.但是,用我的帐户,它报告,接口名称未注册路由器.我认为,我需要以管理员身份执行os.syste...

在python中,我要执行cmd命令:
os.system("netsh interface set interface \"Local Area Connection\" disable")
断开互联网连接.但是,用我的帐户,它报告,接口名称未注册路由器.我认为,我需要以管理员身份执行os.system.但我不知道如何使用它作为管理员!所以,你能帮我吗!谢谢.
解决方法:
要在Windows上以管理员身份运行命令,您可以使用Windows runas命令(我现在无法访问Windows计算机,但是也许..);
import subprocess
subprocess.call(['runas', '/user:Administrator', 'Your command'])
沃梦达教程
本文标题为:如何在Windows 7和admin上使用Python执行cmd命令


基础教程推荐
猜你喜欢
- Python re.findall中正则表达式(.*?)和参数re.S使用 2022-09-02
- Windows下安装Anaconda+Python 2023-09-03
- Pygame实现小球躲避实例代码 2023-08-05
- Python命令行参数解析包argparse的使用详解 2022-10-20
- Linux安装python3.6 2023-09-03
- 如果列表后没有足够的连续内存,CPython处理列表的方式如何扩展? 2023-11-11
- python的进程和线程 2023-09-03
- Python 变量命名规则和定义变量详解 2023-08-04
- windows创建定时任务执行python脚本 2023-09-03
- Python 运算符Inplace 与Standard 2022-10-20