• 远程桌面控制组件封装使用的microsoft terminal services active 1.0


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using AxMSTSCLib;


    namespace WinRemoteDesktop
    {
        public partial class SessionPanel : UserControl
        {
            private AxMsRdpClient7NotSafeForScripting axMsRdpc = null;
            private bool m_bLongConnect = true; //长连接
            public string Index;
            public bool LongConnect { get => m_bLongConnect; set => m_bLongConnect = value; }
            public SessionPanel()
            {
                InitializeComponent();
            }

            public void CreateSession(string ServerIps, string Admin, string Password)
            {
                if (axMsRdpc != null)
                {
                    if (axMsRdpc.Connected!=0)
                    {
                        axMsRdpc.Disconnect();
                    }
                    
                    axMsRdpc.Dispose();
                }

                axMsRdpc = new AxMsRdpClient7NotSafeForScripting();
                ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).BeginInit();
                axMsRdpc.Dock = DockStyle.Fill;
                axMsRdpc.Enabled = true;

                // 绑定连接与释放事件
                axMsRdpc.OnConnecting += new EventHandler(this.axMsRdpc_OnConnecting);
                axMsRdpc.OnDisconnected += new IMsTscAxEvents_OnDisconnectedEventHandler(this.axMsRdpc_OnDisconnected);

                this.Controls.Add(axMsRdpc);
                //axMsRdpcForm.WindowState = FormWindowState.Maximized;
                //axMsRdpcForm.Show();
                ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).EndInit();

                // RDP名字
                axMsRdpc.Name = ServerIps;
                // 服务器地址
                axMsRdpc.Server = ServerIps;
                // 远程登录账号
                axMsRdpc.UserName = Admin;
                // 远程端口号
                axMsRdpc.AdvancedSettings7.RDPPort = 3389;
                //axMsRdpc.AdvancedSettings7.ContainerHandledFullScreen = 1;
                // 自动控制屏幕显示尺寸
                //axMsRdpc.AdvancedSettings7.SmartSizing = true;
                // 启用CredSSP身份验证(有些服务器连接没有反应,需要开启这个)
                axMsRdpc.AdvancedSettings7.EnableCredSspSupport = true;
                // 远程登录密码
                axMsRdpc.AdvancedSettings7.ClearTextPassword = Password;
                // 禁用公共模式
                //axMsRdpc.AdvancedSettings7.PublicMode = false;
                // 颜色位数 8,16,24,32
                axMsRdpc.ColorDepth = 32;
                // 开启全屏 true|flase
                axMsRdpc.FullScreen = false;

                SetRdpWithHeight(this.Width, this.Height);

                // 远程连接
                axMsRdpc.Connect();
            }

            private void axMsRdpc_OnDisconnected(object sender, IMsTscAxEvents_OnDisconnectedEvent e)
            {
                if (axMsRdpc == sender)
                {
                    string disconnectedText = string.Format("远程桌面 {0} 连接已断开!", axMsRdpc.Server);
                    axMsRdpc.DisconnectedText = disconnectedText;
                    if (LongConnect)
                    {
                        Global.WinMessage(disconnectedText, "远程连接");
                    }      
                }
            }

            private void axMsRdpc_OnConnecting(object sender, EventArgs e)
            {
                if (axMsRdpc == sender)
                {
                    axMsRdpc.ConnectingText = axMsRdpc.GetStatusText(Convert.ToUInt32(axMsRdpc.Connected));
                }
            }

            public void axMsRdpcDisconnected()
            {
                if (axMsRdpc != null && axMsRdpc.Connected != 0)
                {
                    axMsRdpc.Disconnect();
                }
            }

            public void SetRdpWithHeight(int width, int height)
            {
                axMsRdpc.DesktopWidth = width;
                axMsRdpc.DesktopHeight = height;
            }

            public string GetConnectServer()
            {
                if (axMsRdpc!=null && axMsRdpc.Connected != 0)
                {
                    return axMsRdpc.Server;
                }

                return "";
            }
        }
    }
     

  • 相关阅读:
    D. Divide and Equalize--Codeforces Round 903 (Div. 3)
    windows系统一键开启和关闭虚拟化
    拼多多快捷回复怎么设置
    Java中如何使用策略模式减少 if / else 分支的使用
    【Serverless】Unity快速集成认证服务实现邮件登录
    冰蝎、蚁剑和哥斯拉
    小编推荐几款好用的MySQL开源客户端,建议收藏哦
    ChatGPT AIGC 实现Excel 交叉查找 Index+match 函数
    第三章线性模型
    22. 深度学习 - 自动求导
  • 原文地址:https://blog.csdn.net/du_bingbing/article/details/125535550