我想创建连接到RDP并执行CMD的Python脚本,但我有一些问题:
ImportError: No module named win32com.client
我已经安装了
WMI
,但是找不到在Linux中安装win32com.client模块的任何解决方案,下面是我的代码import win32com.client
conn = wmi.WMI('172.20.23.45', user='Administrator', password='Pass@123')
conn.Win32_Process.Create(CommandLine='mkdir temp')
最佳答案
我建议尝试rdpy,因为它是rdp协议的纯python实现。
以下是他们自述中的一个示例:
简单RDP客户端
from rdpy.protocol.rdp import rdp
class MyRDPFactory(rdp.ClientFactory):
def clientConnectionLost(self, connector, reason):
reactor.stop()
def clientConnectionFailed(self, connector, reason):
reactor.stop()
def buildObserver(self, controller, addr):
class MyObserver(rdp.RDPClientObserver):
def onReady(self):
"""
@summary: Call when stack is ready
"""
#send 'r' key
self._controller.sendKeyEventUnicode(ord(unicode("r".toUtf8(), encoding="UTF-8")), True)
#mouse move and click at pixel 200x200
self._controller.sendPointerEvent(200, 200, 1, true)
def onUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data):
"""
@summary: Notify bitmap update
@param destLeft: xmin position
@param destTop: ymin position
@param destRight: xmax position because RDP can send bitmap with padding
@param destBottom: ymax position because RDP can send bitmap with padding
@param width: width of bitmap
@param height: height of bitmap
@param bitsPerPixel: number of bit per pixel
@param isCompress: use RLE compression
@param data: bitmap data
"""
def onSessionReady(self):
"""
@summary: Windows session is ready
"""
def onClose(self):
"""
@summary: Call when stack is close
"""
return MyObserver(controller)
from twisted.internet import reactor
reactor.connectTCP("XXX.XXX.XXX.XXX", 3389, MyRDPFactory())
reactor.run()
关于python - 无法通过python连接到rdp,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38130811/