RdpHelper类
时间: 2023-09-15 19:16:10 浏览: 56
`RdpHelper` 类是自定义的 C# 类,用于使用 Remote Desktop Services API 连接到远程计算机并截取屏幕截图。以下是 `RdpHelper` 类的基本实现:
```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
using MSTSCLib;
public static class RdpHelper
{
public static Bitmap CaptureScreen(string serverName, string userName, string password)
{
var server = new MsRdpClient8();
server.Server = serverName;
server.UserName = userName;
server.AdvancedSettings2.ClearTextPassword = password;
server.AdvancedSettings2.DisplayConnectionBar = true;
server.AdvancedSettings2.RedirectDrives = false;
server.AdvancedSettings2.RedirectPrinters = false;
server.AdvancedSettings2.RedirectClipboard = true;
server.DesktopWidth = Screen.PrimaryScreen.Bounds.Width;
server.DesktopHeight = Screen.PrimaryScreen.Bounds.Height;
server.ColorDepth = 32;
server.Connect();
server.FullScreen = false;
var bitmap = new Bitmap(server.DesktopWidth, server.DesktopHeight);
var graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size, CopyPixelOperation.SourceCopy);
server.Disconnect();
return bitmap;
}
}
```
该类使用 `MsRdpClient8` 类连接到远程计算机,并使用 `CopyFromScreen` 方法截取屏幕截图。在使用该类之前,需要在项目中添加对 `MSTSCLib` 的引用。
需要注意的是,使用 Remote Desktop Services API 连接到远程计算机需要一定的权限和安全措施,具体实现需要谨慎考虑。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)