Ejemplo n.º 1
0
 public void Dispose()
 {
     try
     {
         if (rdpConnection != null)
         {
             rdpConnection.Disconnect();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
     if (rdpConnection != null)
     {
         rdpConnection.Dispose();
     }
     rdpConnection = null;
     try
     {
         if (form != null)
         {
             form.Close();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
     if (form != null)
     {
         form.Dispose();
     }
     form = null;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 连接Windows远程桌面
        /// </summary>
        /// <param name="server"></param>
        private void ConnectWindowsDesktop(RDSServer server)
        {
            AxMSTSCLib.AxMsRdpClient9NotSafeForScripting rdp = null;

            // 如果Panel中包含子控件,则让远程桌面控件启动连接
            if (currentRDPanel.HasChildren)
            {
                rdp = (AxMSTSCLib.AxMsRdpClient9NotSafeForScripting)currentRDPanel.Controls[0];

                // About Connected https://msdn.microsoft.com/en-us/library/aa382835(v=vs.85).aspx
                if (rdp.Connected == 0)
                {
                    // 防止服务器相关参数变更
                    rdp.Tag    = server.ServerID.ToString();
                    rdp.Name   = "rdp_" + server.ServerID.ToString();
                    rdp.Server = server.ServerAddress;
                    rdp.AdvancedSettings9.RDPPort = server.ServerPort;
                    rdp.UserName = server.UserName;
                    rdp.AdvancedSettings9.ClearTextPassword = EncryptUtils.DecryptServerPassword(server);

                    rdp.Connect();
                }
            }

            // 如果远程桌面控件不存在,则创建
            if (rdp == null)
            {
                rdp        = new AxMSTSCLib.AxMsRdpClient9NotSafeForScripting();
                rdp.Width  = this.splitContainer1.Panel2.Width;
                rdp.Height = this.splitContainer1.Panel2.Height;
                rdp.Dock   = System.Windows.Forms.DockStyle.None;

                currentRDPanel.Controls.Add(rdp);

                rdp.Tag              = server.ServerID.ToString();
                rdp.Name             = "rdp_" + server.ServerID.ToString();
                rdp.Server           = server.ServerAddress;
                rdp.UserName         = server.UserName;
                rdp.CausesValidation = false;
                rdp.AdvancedSettings9.EnableCredSspSupport = true;
                rdp.AdvancedSettings9.RDPPort             = server.ServerPort;
                rdp.AdvancedSettings9.ClearTextPassword   = EncryptUtils.DecryptServerPassword(server);
                rdp.AdvancedSettings9.BandwidthDetection  = true;
                rdp.AdvancedSettings.allowBackgroundInput = 1;
                rdp.ColorDepth       = 32;
                rdp.ConnectingText   = "正在连接";
                rdp.DisconnectedText = "连接已断开";
                rdp.OnConnected     += Rdp_OnConnected;
                rdp.OnDisconnected  += Rdp_OnDisconnected;
                rdp.OnFatalError    += Rdp_OnFatalError;
                rdp.Connect();
            }
        }