Exemplo n.º 1
0
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            //Create New RDP Object
            rdp      = null;
            rdp      = new AxMSTSCLib.AxMsTscAxNotSafeForScripting();
            rdp.Size = new Size(1430, this.Height - 80);

            //Get Selected Node
            TreeNode nodClicked  = e.Node;
            RDP      selectedRDP = repo.Find(x => x.serverName == nodClicked.Text);

            if (selectedRDP.serverIP == "-1")
            {
                return;
            }

            try
            {
                //Check if connection is already open
                foreach (TabPage t in rdpTabs.TabPages)
                {
                    if (t.Text == nodClicked.Text)
                    {
                        throw new InvalidConstraintException("connection is already up");
                    }
                }

                //Building the tab
                TabPage tab = new TabPage(selectedRDP.serverName);

                tab.Controls.Add(rdp);
                rdpTabs.TabPages.Add(tab);

                rdpTabs.SelectedIndex = rdpTabs.TabPages.Count - 1;
                IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
                rdp.Server   = selectedRDP.serverIP;
                rdp.UserName = selectedRDP.username;
                secured.ClearTextPassword = selectedRDP.password;

                rdp.Connect();
            }
            catch (InvalidConstraintException x)
            {
                MessageBox.Show(x.Message, x.Message + " for " + selectedRDP.serverName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch {}

            /*
             * try
             * {
             *  // Check if connected before disconnecting
             *  if (rdp.Connected.ToString() == "1")
             *      rdp.Disconnect();
             * }
             * catch (Exception Ex)
             * {
             *  MessageBox.Show("Error Disconnecting", "Error disconnecting from remote desktop " + txtServer.Text + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }
             */
        }
 public void CrearComponente(string ip, string pass, string user)
 {
     try
     {
         TabPage tabPage;
         AxMSTSCLib.AxMsTscAxNotSafeForScripting remoto;
         tabPage = new TabPage();
         remoto  = new AxMSTSCLib.AxMsTscAxNotSafeForScripting();
         ComponentResourceManager recursos = new System.ComponentModel.ComponentResourceManager(typeof(RemoteDesktopFH));
         ((System.ComponentModel.ISupportInitialize)(remoto)).BeginInit();
         tabPage.Controls.Add(remoto);
         tabPage.Location = new System.Drawing.Point(4, 22);
         tabPage.Name     = listBox1.SelectedItem.ToString();
         tabPage.Padding  = new System.Windows.Forms.Padding(3);
         tabPage.Size     = new System.Drawing.Size(900, 602);
         tabPage.TabIndex = 2;
         tabPage.Text     = listBox1.SelectedItem.ToString();
         tabPage.UseVisualStyleBackColor = true;
         //
         // RDP
         //
         remoto.Dock     = DockStyle.Fill;
         remoto.Enabled  = true;
         remoto.Location = new System.Drawing.Point(3, 3);
         remoto.Name     = "RDP";
         remoto.OcxState = ((System.Windows.Forms.AxHost.State)(recursos.GetObject("RDP.OcxState")));
         remoto.Size     = new System.Drawing.Size(894, 596);
         remoto.TabIndex = 0;
         this.tabControl1.Controls.Add(tabPage);
         ((System.ComponentModel.ISupportInitialize)(remoto)).EndInit();
         remoto.Server   = ip;
         remoto.UserName = user;
         MSTSCLib.IMsTscNonScriptable secured = (MSTSCLib.IMsTscNonScriptable)remoto.GetOcx();
         secured.ClearTextPassword = pass;
         remoto.Connect();
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 3
0
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            //Create New RDP Object
            rdp=null;
            rdp = new AxMSTSCLib.AxMsTscAxNotSafeForScripting();
            rdp.Size = new Size(1430, this.Height-80);

            //Get Selected Node
            TreeNode nodClicked = e.Node;
            RDP selectedRDP = repo.Find(x => x.serverName == nodClicked.Text);
            if (selectedRDP.serverIP == "-1")
                return;

            try
            {
                //Check if connection is already open
                foreach (TabPage t in rdpTabs.TabPages)
                    if (t.Text == nodClicked.Text)
                        throw new InvalidConstraintException("connection is already up");

                //Building the tab
                TabPage tab = new TabPage(selectedRDP.serverName);

                tab.Controls.Add(rdp);
                rdpTabs.TabPages.Add(tab);

                rdpTabs.SelectedIndex = rdpTabs.TabPages.Count - 1;
                IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
                rdp.Server = selectedRDP.serverIP;
                rdp.UserName = selectedRDP.username;
                secured.ClearTextPassword = selectedRDP.password;

                rdp.Connect();
            }
            catch (InvalidConstraintException x)
            {
                MessageBox.Show(x.Message, x.Message + " for " + selectedRDP.serverName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch{}
            /*
            try
            {
                // Check if connected before disconnecting
                if (rdp.Connected.ToString() == "1")
                    rdp.Disconnect();
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Error Disconnecting", "Error disconnecting from remote desktop " + txtServer.Text + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            */
        }