Esempio n. 1
0
        private void RDC_Event_OnEnterFullScreenMode(object sender, EventArgs e)
        {
            AxMsRdpClient7NotSafeForScripting rdc = sender as AxMsRdpClient7NotSafeForScripting;

            if (rdp2formMap.ContainsKey(rdc.Name))
            {
                Form form = rdp2formMap[rdc.Name];
                form.WindowState = FormWindowState.Minimized;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 创建远程桌面连接
        /// </summary>
        /// <param name="args">参数数组 new string[] { ServerIp, UserName, Password }</param>
        private void CreateAxMsRdpClient(string[] args)
        {
            string[] ServerIps = args[0].Split(':');

            Form form = new Form();

            form.ShowIcon = false;
            //form.StartPosition = FormStartPosition.Manual;
            form.Name = ServerIps[0].Replace(".", "");
            form.Text = string.Format("{0} ({1})", args[3], ServerIps[0]);
            form.Size = new Size(1024, 768);

            Rectangle ScreenArea = Screen.PrimaryScreen.Bounds;
            AxMsRdpClient7NotSafeForScripting axMsRdpc = new AxMsRdpClient7NotSafeForScripting();

            ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).BeginInit();
            axMsRdpc.Dock    = DockStyle.Fill;
            axMsRdpc.Enabled = true;
            axMsRdpc.Name    = string.Format("axMsRdpc_{0}", ServerIps[0].Replace(".", ""));

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

            form.Controls.Add(axMsRdpc);
            form.Show();
            ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).EndInit();

            // 服务器地址
            axMsRdpc.Server = ServerIps[0];
            // 远程登录账号
            axMsRdpc.UserName = args[1];
            // 远程端口号
            axMsRdpc.AdvancedSettings7.RDPPort = ServerIps.Length == 1 ? 3389 : Convert.ToInt32(ServerIps[1]);
            // 自动控制屏幕显示尺寸
            //axMsRdpc.AdvancedSettings9.SmartSizing = true;
            // 启用CredSSP身份验证(有些服务器连接没有反应,需要开启这个)
            axMsRdpc.AdvancedSettings7.EnableCredSspSupport = true;
            // 远程登录密码
            axMsRdpc.AdvancedSettings7.ClearTextPassword = args[2];
            // 颜色位数 8,16,24,32
            axMsRdpc.ColorDepth = 32;
            // 开启全屏 true|flase
            axMsRdpc.FullScreen = this.isFullScreen;
            // 设置远程桌面宽度为显示器宽度
            axMsRdpc.DesktopWidth = ScreenArea.Width;
            // 设置远程桌面宽度为显示器高度
            axMsRdpc.DesktopHeight = ScreenArea.Height;
            // 远程连接
            axMsRdpc.Connect();
        }
Esempio n. 3
0
            public static string ToDisconnectMessage(AxMsRdpClient7NotSafeForScripting client, int reason)
            {
                switch (reason)
                {
                case 1:
                case 2:
                case 3:
                    // These are normal disconnects and not considered errors.
                    return(String.Empty);

                default:
                    return(client.GetErrorDescription((uint)reason, (uint)client.ExtendedDisconnectReason));
                }
            }
Esempio n. 4
0
        private void RDC_Event_OnDisconnected(object sender, IMsTscAxEvents_OnDisconnectedEvent e)
        {
            AxMsRdpClient7NotSafeForScripting rdc = sender as AxMsRdpClient7NotSafeForScripting;

            if (rdp2formMap.ContainsKey(rdc.Name))
            {
                Form form = rdp2formMap[rdc.Name];
                if (form2rdpMap.ContainsKey(form.Name))
                {
                    form2rdpMap.Remove(form.Name);
                }
                form.Close();
                rdp2formMap.Remove(rdc.Name);
                Trace.TraceInformation("rdm session closed.");
            }
        }
        public RemoteControl_rdp(ContentControl contentControl)
            : base(contentControl)
        {
            InitializeComponent();
            if (CommonServices.OSVersion <= 6.1f)
            {
                MsRdpClient7 = new AxMsRdpClient7NotSafeForScripting();
            }
            else
            {
                MsRdpClient9 = new AxMsRdpClient9NotSafeForScripting();
            }
            //win7 及以下版本
            if (MsRdpClient7 != null)
            {
                MsRdpClient7.BeginInit();
                MsRdpClient7.Dock = System.Windows.Forms.DockStyle.Fill;
                FormsHost.Child   = MsRdpClient7;
                MsRdpClient7.EndInit();

                MsRdpClient7.OnConnected              += MyRdp_OnConnected;
                MsRdpClient7.OnFatalError             += MyRdp_OnFatalError;
                MsRdpClient7.OnLogonError             += MyRdp_OnLogonError;
                MsRdpClient7.OnDisconnected           += MyRdp_OnDisconnected;
                MsRdpClient7.OnRequestGoFullScreen    += MyRdp_OnRequestGoFullScreen;
                MsRdpClient7.OnRequestLeaveFullScreen += MyRdp_OnRequestLeaveFullScreen;
            }
            else
            {
                MsRdpClient9.BeginInit();
                MsRdpClient9.Dock = System.Windows.Forms.DockStyle.Fill;
                FormsHost.Child   = MsRdpClient9;
                MsRdpClient9.EndInit();

                MsRdpClient9.OnConnected              += MyRdp_OnConnected;
                MsRdpClient9.OnFatalError             += MyRdp_OnFatalError;
                MsRdpClient9.OnLogonError             += MyRdp_OnLogonError;
                MsRdpClient9.OnDisconnected           += MyRdp_OnDisconnected;
                MsRdpClient9.OnRequestGoFullScreen    += MyRdp_OnRequestGoFullScreen;
                MsRdpClient9.OnRequestLeaveFullScreen += MyRdp_OnRequestLeaveFullScreen;
            }

            _winRdpClientProc   = WinRdpClientProc;
            _winInRdpClientProc = WinInRdpClientProc;
        }
Esempio n. 6
0
        private void ConnectCore()
        {
            _form = new TestForm();
            _form.Show();
            _ax          = _form.RdpControl;
            _ax.Server   = _context.Server.Name;
            _ax.Domain   = _context.Server.Domain;
            _ax.UserName = _context.Server.Username;
            _ax.AdvancedSettings8.ClearTextPassword = _context.Server.Password;
            _ax.OnConnected    += delegate { _connectedEvent.Set(); };
            _ax.OnDisconnected += AxOnDisconnected;
            _ax.Connect();

            // You need a message loop or else the RDP client control will never connect.
            // That's why we run the form on a separate thread.
            Application.Run(_form);
            _form.Dispose();
        }
Esempio n. 7
0
 private bool InitializeClientControl()
 {
     try
     {
         this.client = new AxMsRdpClient7NotSafeForScripting();
         this.reconecting.AllowDrop = true;
         this.AllowDrop             = true;
         this.client.AllowDrop      = true;
     }
     catch (Exception exception)
     {
         string message = "Please update your RDP client to at least version 7.";
         Log.Info(message, exception);
         MessageBox.Show(message);
         return(false);
     }
     return(true);
 }
        private void ConnectCore()
        {
            _form = new TestForm();
            _form.Show();
            _ax = _form.RdpControl;
            _ax.Server = _context.Server.Name;
            _ax.Domain = _context.Server.Domain;
            _ax.UserName = _context.Server.Username;
            _ax.AdvancedSettings8.ClearTextPassword = _context.Server.Password;
            _ax.OnConnected += delegate { _connectedEvent.Set(); };
            _ax.OnDisconnected += AxOnDisconnected;
            _ax.Connect();

            // You need a message loop or else the RDP client control will never connect.
            // That's why we run the form on a separate thread.
            Application.Run(_form);
            _form.Dispose();
        }
Esempio n. 9
0
        private void connectRemoteDesktop(string loginname, string password, string serverIP, int serverPort = 3389, string title = "")
        {
            Form form = new Form();

            form.ShowIcon = false;
            form.Name     = string.Format("form_rdp_{0}_{1}", serverIP.Replace(".", "_"), DateTime.Now.Second.ToString());
            form.Text     = title;
            form.Size     = new Size(1024, 768);
            form.Resize  += new System.EventHandler(this.RDPForm_Resize);
            form.Closing += new CancelEventHandler(this.RDPForm_Closing);

            Rectangle ScreenArea = Screen.PrimaryScreen.Bounds;
            AxMsRdpClient7NotSafeForScripting axMsRdpc = new AxMsRdpClient7NotSafeForScripting();

            ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).BeginInit();
            axMsRdpc.Dock    = DockStyle.Fill;
            axMsRdpc.Enabled = true;
            axMsRdpc.Name    = string.Format("axMsRdpc_{0}_{1}", serverIP.Replace(".", "_"), DateTime.Now.Second.ToString());

            // bind rdp connect's events
            axMsRdpc.OnDisconnected        += RDC_Event_OnDisconnected;
            axMsRdpc.OnLeaveFullScreenMode += RDC_Event_OnLeaveFullScreenMode;
            axMsRdpc.OnEnterFullScreenMode += RDC_Event_OnEnterFullScreenMode;

            form.Controls.Add(axMsRdpc);
            form.Show();
            ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).EndInit();

            axMsRdpc.Server   = serverIP;
            axMsRdpc.UserName = loginname;
            axMsRdpc.AdvancedSettings7.RDPPort = Convert.ToInt32(serverPort);
            //axMsRdpc.AdvancedSettings9.SmartSizing = true;
            axMsRdpc.AdvancedSettings7.EnableCredSspSupport = true;
            axMsRdpc.AdvancedSettings7.ClearTextPassword    = password;
            axMsRdpc.ColorDepth    = 32;
            axMsRdpc.FullScreen    = true;
            axMsRdpc.DesktopWidth  = ScreenArea.Width;
            axMsRdpc.DesktopHeight = ScreenArea.Height;
            axMsRdpc.Connect();

            rdp2formMap.Add(axMsRdpc.Name, form);
            form2rdpMap.Add(form.Name, axMsRdpc);
        }
Esempio n. 10
0
        private void RDC_Event_OnLeaveFullScreenMode(object sender, EventArgs e)
        {
            AxMsRdpClient7NotSafeForScripting rdc = sender as AxMsRdpClient7NotSafeForScripting;

            if (rdp2formMap.ContainsKey(rdc.Name))
            {
                Form form = rdp2formMap[rdc.Name];
                if (form.WindowState != FormWindowState.Normal)
                {
                    form.WindowState = FormWindowState.Normal;
                }

                if (form.Location.Y < 0)
                {
                    form.Location = new Point(form.Location.X, 10);
                }
                if (form.Location.X < 0)
                {
                    form.Location = new Point(10, form.Location.Y);
                }
            }
        }
Esempio n. 11
0
        private void axMsRdpc_OnDisconnected(object sender, IMsTscAxEvents_OnDisconnectedEvent e)
        {
            AxMsRdpClient7NotSafeForScripting axMsRdpc = (AxMsRdpClient7NotSafeForScripting)sender;

            axMsRdpc.DisconnectedText = "连接失败,连接已断开!请关闭重试!";
        }
Esempio n. 12
0
        private void axMsRdpc_OnConnecting(object sender, EventArgs e)
        {
            AxMsRdpClient7NotSafeForScripting axMsRdpc = (AxMsRdpClient7NotSafeForScripting)sender;

            axMsRdpc.ConnectingText = axMsRdpc.GetStatusText(Convert.ToUInt32(axMsRdpc.Connected));
        }
Esempio n. 13
0
        /// <summary>
        /// 创建远程桌面连接
        /// </summary>
        /// <param name="args">参数数组 new string[] { ServerIp, UserName, Password }</param>
        private void CreateAxMsRdpClient(string[] args)
        {
            string[] ServerIps = args[0].Split(':');

            Form axMsRdpcForm = new Form();

            axMsRdpcForm.ShowIcon = false;
            //axMsRdpcForm.StartPosition = FormStartPosition.Manual;
            axMsRdpcForm.Name        = string.Format("Form_{0}", ServerIps[0].Replace(".", ""));
            axMsRdpcForm.Text        = string.Format("{0} ({1})", args[3], ServerIps[0]);
            axMsRdpcForm.Size        = new Size(1024, 768);
            axMsRdpcForm.FormClosed += new FormClosedEventHandler(this.axMsRdpcForm_Closed);

            //Rectangle ScreenArea = Screen.PrimaryScreen.Bounds;
            // 给axMsRdpc取个名字
            string _axMsRdpcName = string.Format("axMsRdpc_{0}", ServerIps[0].Replace(".", ""));

            if (axMsRdpcArray.Contains(_axMsRdpcName))
            {
                Global.WinMessage("此远程已经连接,请勿重复连接!"); return;
            }
            else
            {
                axMsRdpc = new AxMsRdpClient7NotSafeForScripting();
            }
            // 添加到当前缓存
            axMsRdpcArray.Add(_axMsRdpcName);

            ((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);

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

            // RDP名字
            axMsRdpc.Name = _axMsRdpcName;
            // 服务器地址
            axMsRdpc.Server = ServerIps[0];
            // 远程登录账号
            axMsRdpc.UserName = args[1];
            // 远程端口号
            axMsRdpc.AdvancedSettings7.RDPPort = ServerIps.Length == 1 ? 3389 : Convert.ToInt32(ServerIps[1]);
            //axMsRdpc.AdvancedSettings7.ContainerHandledFullScreen = 1;
            // 自动控制屏幕显示尺寸
            //axMsRdpc.AdvancedSettings7.SmartSizing = true;
            // 启用CredSSP身份验证(有些服务器连接没有反应,需要开启这个)
            axMsRdpc.AdvancedSettings7.EnableCredSspSupport = true;
            // 远程登录密码
            axMsRdpc.AdvancedSettings7.ClearTextPassword = args[2];
            // 禁用公共模式
            //axMsRdpc.AdvancedSettings7.PublicMode = false;
            // 颜色位数 8,16,24,32
            axMsRdpc.ColorDepth = 32;
            // 开启全屏 true|flase
            axMsRdpc.FullScreen = this.isFullScreen;
            // 设置远程桌面宽度为显示器宽度
            //axMsRdpc.DesktopWidth = ScreenArea.Width;
            axMsRdpc.DesktopWidth = axMsRdpcForm.ClientRectangle.Width;
            // 设置远程桌面宽度为显示器高度
            //axMsRdpc.DesktopHeight = ScreenArea.Height;
            axMsRdpc.DesktopHeight = axMsRdpcForm.ClientRectangle.Height;
            // 远程连接
            axMsRdpc.Connect();
        }
        public override bool SetProps()
        {
            base.SetProps();

            try
            {
                RDP_Client = (AxMsRdpClient7NotSafeForScripting)this.Control;
                Info = this.InterfaceControl.Info;

                try
                {
                    RDP_Client.CreateControl();

                    while (!this.RDP_Client.Created)
                    {
                        Thread.Sleep(10);
                        Application.DoEvents();
                    }
                }
                catch (System.Runtime.InteropServices.COMException comEx)
                {
                    Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg,
                                                        Language.strRdpControlCreationFailed + Constants.vbNewLine +
                                                        Constants.vbNewLine + comEx.Message);
                    RDP_Client.Dispose();
                    return false;
                }

                this.RDPVersion = new Version((string)RDP_Client.Version);

                RDP_Client.Server = this.Info.Hostname;

                this.SetCredentials();
                this.SetResolution();
                this.RDP_Client.FullScreenTitle = this.Info.Name;

                //not user changeable
                RDP_Client.AdvancedSettings2.GrabFocusOnConnect = true;
                RDP_Client.AdvancedSettings3.EnableAutoReconnect = true;
                RDP_Client.AdvancedSettings3.MaxReconnectAttempts = Settings.Default.RdpReconnectionCount;
                RDP_Client.AdvancedSettings2.keepAliveInterval = 60000; //in milliseconds (10.000 = 10 seconds)
                RDP_Client.AdvancedSettings5.AuthenticationLevel = 0;
                RDP_Client.AdvancedSettings6.EncryptionEnabled = 1;

                RDP_Client.AdvancedSettings2.overallConnectionTimeout = 20;

                RDP_Client.AdvancedSettings2.BitmapPeristence = Convert.ToInt32(this.Info.CacheBitmaps);
                RDP_Client.AdvancedSettings7.EnableCredSspSupport = Info.UseCredSsp;

                this.SetUseConsoleSession();
                this.SetPort();
                this.SetRedirectKeys();
                this.SetRedirection();
                this.SetAuthenticationLevel();
                this.SetRDGateway();

                RDP_Client.ColorDepth = (int)(this.Info.Colors);

                this.SetPerformanceFlags();

                RDP_Client.ConnectingText = Language.strConnecting;

                Control.Anchor = AnchorStyles.None;

                return true;
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg,
                                                    Language.strRdpSetPropsFailed + Constants.vbNewLine + ex.Message,
                                                    true);
                return false;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 打开远程桌面窗口连接给定ip的windows主机
        /// </summary>
        public static void OpenRemoteDesktop(RemoteDesktopInput input)
        {
            UIThread.Execute(() => {
                string serverIp                = input.ServerIp;
                string userName                = input.UserName;
                string password                = input.Password;
                string description             = input.Description;
                Action <string> onDisconnected = input.OnDisconnected;
                string[] serverIps             = serverIp.Split(':');
                serverIp        = serverIps[0];
                string id       = serverIp.Replace(".", "");
                string formName = $"form_{id}";
                string formText = $"开源矿工远程桌面 - {description} ({serverIp})";
                AxMsRdpClient7NotSafeForScripting axMsRdpc = null;
                string axMsRdpcName = $"axMsRdpc_{id}";
                if (SFormsByName.ContainsKey(formName))
                {
                    Form form = SFormsByName[formName];
                    form.Show();
                    if (form.WindowState == FormWindowState.Minimized)
                    {
                        form.WindowState = FormWindowState.Normal;
                    }
                    form.Activate();
                    return;
                }
                else
                {
                    axMsRdpc = new AxMsRdpClient7NotSafeForScripting();
                }
                Form axMsRdpcForm = new Form {
                    ShowIcon      = false,
                    Name          = formName,
                    Text          = formText,
                    Size          = new Size(1200, 900),
                    StartPosition = FormStartPosition.CenterScreen,
                    MaximizeBox   = false,
                    WindowState   = FormWindowState.Normal
                };
                axMsRdpcForm.FormClosed += (object sender, FormClosedEventArgs e) => {
                    Form frm = (Form)sender;
                    foreach (Control ctrl in frm.Controls)
                    {
                        if (ctrl.GetType().Name == nameof(AxMsRdpClient7NotSafeForScripting))
                        {
                            if (SFormsByName.ContainsKey(frm.Name))
                            {
                                SFormsByName.Remove(frm.Name);
                            }
                            var axMsRdp = (AxMsRdpClient7NotSafeForScripting)ctrl;
                            if (axMsRdp != null && axMsRdp.Connected != 0)
                            {
                                axMsRdp.Disconnect();
                                axMsRdp.Dispose();
                            }
                        }
                    }
                };
                SFormsByName.Add(formName, axMsRdpcForm);

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

                axMsRdpc.OnConnecting += (object sender, EventArgs e) => {
                    var axMsRdp                    = sender as AxMsRdpClient7NotSafeForScripting;
                    axMsRdp.ConnectingText         = axMsRdp.GetStatusText(Convert.ToUInt32(axMsRdp.Connected));
                    axMsRdp.FindForm().WindowState = FormWindowState.Normal;
                };
                axMsRdpc.OnDisconnected += (object sender, IMsTscAxEvents_OnDisconnectedEvent e) => {
                    var axMsRdp              = sender as AxMsRdpClient7NotSafeForScripting;
                    string disconnectedText  = $"{formText}远程桌面连接已断开!";
                    axMsRdp.DisconnectedText = disconnectedText;
                    axMsRdp.FindForm().Close();
                    Write.UserFail(disconnectedText);
                    onDisconnected?.Invoke(disconnectedText);
                };

                axMsRdpcForm.Controls.Add(axMsRdpc);
                axMsRdpcForm.Show();
                ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).EndInit();

                axMsRdpc.Name     = axMsRdpcName;
                axMsRdpc.Server   = serverIp;
                axMsRdpc.UserName = userName;
                axMsRdpc.AdvancedSettings7.RDPPort = serverIps.Length == 1 ? 3389 : Convert.ToInt32(serverIps[1]);
                // 启用CredSSP身份验证(有些服务器连接没有反应,需要开启这个)
                axMsRdpc.AdvancedSettings7.EnableCredSspSupport = true;
                axMsRdpc.AdvancedSettings7.ClearTextPassword    = password;
                // 禁用公共模式
                //axMsRdpc.AdvancedSettings7.PublicMode = false;
                // 颜色位数 8,16,24,32
                axMsRdpc.ColorDepth    = 32;
                axMsRdpc.FullScreen    = false;
                axMsRdpc.DesktopWidth  = axMsRdpcForm.ClientRectangle.Width;
                axMsRdpc.DesktopHeight = axMsRdpcForm.ClientRectangle.Height;
                axMsRdpc.Connect();
            });
        }
        public override bool SetProps()
        {
            base.SetProps();

            try
            {
                RDP_Client = (AxMsRdpClient7NotSafeForScripting)this.Control;
                Info       = this.InterfaceControl.Info;

                try
                {
                    RDP_Client.CreateControl();

                    while (!this.RDP_Client.Created)
                    {
                        Thread.Sleep(10);
                        System.Windows.Forms.Application.DoEvents();
                    }
                }
                catch (System.Runtime.InteropServices.COMException comEx)
                {
                    Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg,
                                                        Language.strRdpControlCreationFailed + Constants.vbNewLine +
                                                        Constants.vbNewLine + comEx.Message);
                    RDP_Client.Dispose();
                    return(false);
                }

                this.RDPVersion = new Version((string)RDP_Client.Version);

                RDP_Client.Server = this.Info.Hostname;

                this.SetCredentials();
                this.SetResolution();
                this.RDP_Client.FullScreenTitle = this.Info.Name;

                //not user changeable
                RDP_Client.AdvancedSettings2.GrabFocusOnConnect   = true;
                RDP_Client.AdvancedSettings3.EnableAutoReconnect  = true;
                RDP_Client.AdvancedSettings3.MaxReconnectAttempts = Settings.Default.RdpReconnectionCount;
                RDP_Client.AdvancedSettings2.keepAliveInterval    = 60000; //in milliseconds (10.000 = 10 seconds)
                RDP_Client.AdvancedSettings5.AuthenticationLevel  = 0;
                RDP_Client.AdvancedSettings6.EncryptionEnabled    = 1;

                RDP_Client.AdvancedSettings2.overallConnectionTimeout = 20;

                RDP_Client.AdvancedSettings2.BitmapPeristence     = Convert.ToInt32(this.Info.CacheBitmaps);
                RDP_Client.AdvancedSettings7.EnableCredSspSupport = Info.UseCredSsp;

                this.SetUseConsoleSession();
                this.SetPort();
                this.SetRedirectKeys();
                this.SetRedirection();
                this.SetAuthenticationLevel();
                this.SetRDGateway();

                RDP_Client.ColorDepth = (int)(this.Info.Colors);

                this.SetPerformanceFlags();

                RDP_Client.ConnectingText = Language.strConnecting;

                Control.Anchor = AnchorStyles.None;

                return(true);
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg,
                                                    Language.strRdpSetPropsFailed + Constants.vbNewLine + ex.Message,
                                                    true);
                return(false);
            }
        }
Esempio n. 17
0
            public static string ToDisconnectMessage(AxMsRdpClient7NotSafeForScripting client, int reason)
            {
                switch (reason)
                {
                    case 1:
                    case 2:
                    case 3:
                        // These are normal disconnects and not considered errors.
                        return String.Empty;

                    default:
                        return client.GetErrorDescription((uint)reason, (uint)client.ExtendedDisconnectReason);
                }
            }
Esempio n. 18
0
        private void connectRemoteDesktop(string loginname, string password, string serverIP, int serverPort = 3389, string title = "", bool useMultimon = false)
        {
            Form form = new Form();

            form.ShowIcon = false;
            form.Name     = string.Format("form_rdp_{0}_{1}", serverIP.Replace(".", "_"), DateTime.Now.Second.ToString());
            form.Text     = title;
            form.Size     = new Size(1024, 768);
            form.Resize  += new System.EventHandler(this.RDPForm_Resize);
            form.Closing += new CancelEventHandler(this.RDPForm_Closing);

            Rectangle ScreenArea;

            if (Screen.AllScreens.Length > 1)
            {
                Trace.TraceInformation("Screen Count = {0}", Screen.AllScreens.Length);
                Screen scr = null;
                for (int i = 0; i < Screen.AllScreens.Length; i++)
                {
                    scr = Screen.AllScreens[i];
                    Trace.TraceInformation("Screen[{0}]:Primary = {1}", i, scr.Primary);
                    if (scr.Primary)
                    {
                        break;
                    }
                }
                if (scr != null)
                {
                    ScreenArea = scr.Bounds;
                    Trace.TraceInformation("set ScreenArea:width={0} , height={1}", ScreenArea.Width, ScreenArea.Height);
                }
                else
                {
                    ScreenArea = Screen.PrimaryScreen.Bounds;
                }
            }
            else
            {
                ScreenArea = Screen.PrimaryScreen.Bounds;
            }
            AxMsRdpClient7NotSafeForScripting axMsRdpc = new AxMsRdpClient7NotSafeForScripting();

            ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).BeginInit();
            axMsRdpc.Dock    = DockStyle.Fill;
            axMsRdpc.Enabled = true;
            axMsRdpc.Name    = string.Format("axMsRdpc_{0}_{1}", serverIP.Replace(".", "_"), DateTime.Now.Second.ToString());

            // bind rdp connect's events
            axMsRdpc.OnDisconnected        += RDC_Event_OnDisconnected;
            axMsRdpc.OnLeaveFullScreenMode += RDC_Event_OnLeaveFullScreenMode;
            axMsRdpc.OnEnterFullScreenMode += RDC_Event_OnEnterFullScreenMode;

            form.Controls.Add(axMsRdpc);
            form.Show();
            ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).EndInit();

            IMsRdpClientNonScriptable5 sc = (IMsRdpClientNonScriptable5)axMsRdpc.GetOcx();

            sc.UseMultimon = useMultimon;

            axMsRdpc.Server   = serverIP;
            axMsRdpc.UserName = loginname;
            axMsRdpc.AdvancedSettings7.RDPPort = Convert.ToInt32(serverPort);
            axMsRdpc.AdvancedSettings7.EnableCredSspSupport = true;
            axMsRdpc.AdvancedSettings7.ClearTextPassword    = password;
            axMsRdpc.AdvancedSettings7.Compress             = 1;
            //axMsRdpc.AdvancedSettings7.SmartSizing = true; //自动缩放图像
            axMsRdpc.AdvancedSettings7.ContainerHandledFullScreen = 0;

            axMsRdpc.ColorDepth = 32;
            axMsRdpc.FullScreen = true;
            Trace.TraceInformation("ScreenArea:width={0} , height={1}", ScreenArea.Width, ScreenArea.Height);
            axMsRdpc.DesktopWidth  = ScreenArea.Width;
            axMsRdpc.DesktopHeight = ScreenArea.Height;

            axMsRdpc.Connect();

            rdp2formMap.Add(axMsRdpc.Name, form);
            form2rdpMap.Add(form.Name, axMsRdpc);
        }