import winrm

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

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"}
04-25 04:20