.net 远程桌面

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
public class RdpConnect : UserControl
{
    AxMSTSCLib.AxMsRdpClient9NotSafeForScripting _rdpClient;

    public AxMsRdpClient9NotSafeForScripting Rdp => _rdpClient;

    public RdpConnect()
    {
        InitializeComponent();

        _rdpClient = new AxMsRdpClient9NotSafeForScripting();
        _rdpClient.Dock = DockStyle.Fill;
        this.Controls.Add(_rdpClient);
    }

    public void Connect(string server, string userName, string passwd, int port = 3389)
    {
        _rdpClient.Server = server;//服务器地址

        object otrue = true;
        try
        {
            /*
            https://learn.microsoft.com/zh-cn/windows/win32/termserv/child-sessions?redirectedfrom=MSDN
            只能在连接之前使用 远程桌面 ActiveX 控件 并将“ConnectToChildSession”属性与 IMsRdpExtendedSettings.Property 一起从现有用户的会话中创建子会话。*/
            var settings = (_rd pClient.GetOcx() as IMsRdpExtendedSettings);
            settings.set_Property("ConnectToChildSession", ref otrue);
        }
        catch (Exception ex)
        {
            Trace.WriteLine(ex);
        }

        _rdpClient.UserName = userName;
        _rdpClient.AdvancedSettings9.RDPPort = port;
        _rdpClient.AdvancedSettings9.ClearTextPassword = passwd;//密码
        _rdpClient.ConnectingText = $"正在连接[{_rdpClient.Server}],请稍等... ";


        //https://www.cnblogs.com/05-hust/articles/11990057.html
        _rdpClient.AdvancedSettings9.EnableCredSspSupport = true;
        _rdpClient.AdvancedSettings9.NegotiateSecurityLayer = true;
        _rdpClient.AdvancedSettings9.RedirectDrives = true;//加载本地磁盘
        _rdpClient.AdvancedSettings9.RedirectPrinters = true;//加载打印机
        _rdpClient.AdvancedSettings9.RedirectSmartCards = true;//加载sd卡
        _rdpClient.AdvancedSettings9.ConnectToServerConsole = true;
        _rdpClient.AdvancedSettings9.SmartSizing = true;

        _rdpClient.ColorDepth = 16;//颜色位数
        //rdpClient.ColorDepth = 32;

        //rdpClient.FullScreen = true;//是否全屏

        // rdp事件
        //rdpClient.OnConnected += RdpClient_OnConnected;
        //rdpClient.OnChannelReceivedData += RdpClient_OnChannelReceivedData;
        //rdpClient.OnConnecting += RdpClient_OnConnecting;
        //rdpClient.OnDisconnected += RdpClient_OnDisconnected;
        //rdpClient.OnAuthenticationWarningDisplayed += RdpClient_OnAuthenticationWarningDisplayed;
        //rdpClient.OnFatalError += RdpClient_OnFatalError;
        //rdpClient.OnFocusReleased += RdpClient_OnFocusReleased;
        //rdpClient.OnLoginComplete += RdpClient_OnLoginComplete;
        //rdpClient.OnLogonError += RdpClient_OnLogonError;
        //rdpClient.OnWarning += RdpClient_OnWarning;


        _rdpClient.Connect();
    }

    private void InitializeComponent()
    {
        this.SuspendLayout();
        //
        // RdpConnect
        //
        this.Name = "RdpConnect";
        this.Size = new System.Drawing.Size(547, 373);
        this.ResumeLayout(false);

    }
}

调用:

1
2
3
4
5
RdpConnect rdpConnect = new RdpConnect();
rdpConnect.Dock = DockStyle.Fill;
this.panel2.Controls.Add(rdpConnect);

rdpConnect.Connect("127.75.42.180", System.Environment.MachineName + "\\Administrator", "123qwe88");

组件

RPA 竞品

RPA工具列表

开源项目


其他不开源的竞品