robin2015
11/13/2019 - 9:28 AM

winrm服务的相关配置

winrm service 的基础配置,执行之后提示选择的时候选中y:
winrm quickconfig

查看winrm service listener(分为http和https):
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"}


查看winrm服务的配置:
winrm get winrm/config

import winrm

wintest = winrm.Session('http://47.103.144.112:5985/wsman', auth=("administrator", "xxxxx"))
# # 9068为远程运行python进程pid
# r = wintest.run_ps(r"""cd C:\Users\Administrator\Documents\GitHub\pytdx-Ycyj\ycyj_kline
# python app.py
# """)  # 会卡住,线程单独执行,线程关闭后远程不会关闭
# pprint(r.std_out)
##################################
# 1、查看某个进程操作:
# netstat -aon|findstr xxx (xxx端口号)
# 2、关闭该进程:
# taskkill -f -pid aaa(aaa为该端口的进程pid号)

r = wintest.run_ps('''netstat -aon|findstr 80''')
out_str = r.std_out.decode('utf-8')
print(out_str)

import re
matchObj = re.search(r'([0-9]{2,}\r\n)', out_str)
if matchObj:
    print('pid:', matchObj.group(1))