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"}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM