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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值