Python远程连接Windows,并调用Windows命令(类似于paramiko)

import winrm

win2012 = winrm.Session('http://192.168.0.19:5985/wsman',auth=('wt','635870838'))


r = win2012.run_cmd('D: &'
                    ' cd python &'
                    ' type s.txt &'
 ' net stop iphlpsvc
') # net stop iphlpsvc 是关闭iphlpsvc服务 print(r.std_out.decode()) # 打印获取到的信息 print(r.std_err) #打印错误信息 注意:需要在被控机上开启以下服务: 针对winrm service 进行基础配置: winrm quickconfig 查看winrm service listener: winrm e winrm/config/listener 为winrm service 配置auth: winrm set winrm/config/service/auth @{Basic="true"} 为winrm service 配置加密方式为允许非加密: winrm set winrm/config/service @{AllowUnencrypted="true"}

 

posted @ 2017-04-24 16:07  明天OoO你好  阅读(12829)  评论(1编辑  收藏  举报