• 远程桌面控制组件封装使用的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 "";
            }
        }
    }
     

  • 相关阅读:
    【六】【SQL】多表查询,笛卡尔积
    牛客网刷题记录 || 第一番
    【三维重建】3D Gaussian Splatting:实时的神经场渲染
    Java:实现动态数组类算法(附完整源码)
    澜沧古茶在港交所上市申请失效:收入不及八马茶业,股东提前套现
    质量小议16 -- 白盒测试方法
    vb.net 实时监控双门双向门禁控制板源代码
    Ubuntu:解决PyCharm中不能输入中文或者输入一个中文解决方法
    SpringBoot MyBatisPlus Oracle
    Java框架(八)--SpringMVC拦截器(1)--拦截器开发流程、多Interceptor执行顺序及preHandle返回值
  • 原文地址:https://blog.csdn.net/du_bingbing/article/details/125535550