VC++利用微软mstscax.dll控件集成远程桌面

8 篇文章 0 订阅
利用微软mstscax.dll控件集成远程桌面


1. 新建基于MFC的对话框程序,在对话框资源上右键,选择【Insert ActiveX Control...】菜单,然后在弹出的界面中选择“Microsoft RDP Client Contorl”。


2.在新添加的控件上点击右键选择【Add Variable...】,为该控件绑定一个变量,本例子中为m_RemoteDesktopControl。



3.打开Class Wizard,选择右上角【Add Class】按钮的下拉部分,在弹出的下拉列表中选择【MFC Class From TypeLib...】,然后在类库列表中选择Microsoft Terminal Service Client Control Type Library,然后在左下侧接口列表中选择IMsRdpClientAdvanceSettings6,添加到右侧生成类列表中。


4.打开CMsRdpClientAdvancedSettings6类头文件,注释掉#import "C:\\Windows\\SysWOW64\\mstscax.dll" no_namespace这句代码。

连接代码:
CMsRdpClientAdvancedSettings6 m_MsRdpClientAdvancedSettings(m_RemoteDesktopControl.get_AdvancedSettings());
	m_RemoteDesktopControl.put_Server(_T("10.176.36.181"));
	m_RemoteDesktopControl.put_UserName(_T("Leen"));
	m_RemoteDesktopControl.put_DesktopHeight(800);
	m_RemoteDesktopControl.put_DesktopWidth(1200);
	m_RemoteDesktopControl.put_ColorDepth(32);
	m_MsRdpClientAdvancedSettings.put_Compress(1);
	m_MsRdpClientAdvancedSettings.put_BitmapPeristence(1);
	m_MsRdpClientAdvancedSettings.put_ClearTextPassword(_T("******"));
	m_MsRdpClientAdvancedSettings.put_singleConnectionTimeout(20);
	m_RemoteDesktopControl.put_ConnectingText(_T("Loading..."));
	m_RemoteDesktopControl.Connect();


  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
下面是一个使用 `ctypes` 模块调用 Windows 10 远程桌面的示例代码: ```python import ctypes # 加载 Windows API 库 mstscax = ctypes.WinDLL('mstscax.dll') kernel32 = ctypes.WinDLL('kernel32.dll') # 定义 Windows API 函数的参数类型 DWORD = ctypes.c_ulong LPWSTR = ctypes.c_wchar_p HWND = ctypes.c_void_p # 获取当前窗口句柄 hWnd = kernel32.GetConsoleWindow() # 创建 MSTSCax 控件 mstsc = ctypes.windll.ole32.CoCreateInstance( ctypes.byref(ctypes.wintypes.GUID("{905E63B6-C1BF-494E-B29C-65B732D3D21A}")), None, 1, ctypes.byref(ctypes.wintypes.GUID("{0F6B957E-509E-11D1-A7CC-0000F87571E3}")), ctypes.byref(mstscax), ) # 设置 MSTSCax 控件的属性 mstscax.put_Server(LPWSTR("example.com")) mstscax.put_UserName(LPWSTR("username")) mstscax.put_Domain(LPWSTR("domain")) mstscax.put_Password(LPWSTR("password")) # 连接远程桌面 mstscax.Connect() # 获取 MSTSCax 控件的窗口句柄 hWndMstsc = mstscax.get_HWND() # 将 MSTSCax 控件嵌入到当前窗口 mstscax.SetParent(hWnd, 0) mstscax.MoveWindow(0, 0, 800, 600, True) mstscax.put_Visible(True) # 消息循环 msg = ctypes.wintypes.MSG() while ctypes.windll.user32.GetMessageW(ctypes.byref(msg), None, 0, 0) > 0: ctypes.windll.user32.TranslateMessage(ctypes.byref(msg)) ctypes.windll.user32.DispatchMessageW(ctypes.byref(msg)) ``` 在上面的代码中,我们使用 `ctypes.WinDLL` 函数来加载 `mstscax.dll` 和 `kernel32.dll` 库。然后,我们使用 `ctypes.windll.ole32.CoCreateInstance` 函数创建了一个 MSTSCax 控件,并设置了它的属性。最后,我们将 MSTSCax 控件嵌入到当前窗口,并启动了一个消息循环来处理窗口消息。 请注意,使用 `ctypes` 模块调用 Windows API 可能会比使用 pywin32 模块更复杂,并且需要手动定义 Windows API 函数的参数类型。但是,它可以在 Python 3.10 中正常工作,并且可以访问 Windows API 的所有功能。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Leen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值