Esempio n. 1
0
        public void Read()
        {
            string sql = "SELECT * FROM Servers";

            //using (SQLiteConnection conn = new SQLiteConnection())
            //{

            //}

            string result = base.ExecuteQuery(sql, null);

            this.ArrayListServers.Clear();

            if (result == string.Empty)
            {
                if (base.Database.Reader.HasRows)
                {
                    while (base.Database.Reader.Read())
                    {
                        Model_ServerDetails sd = new Model_ServerDetails()
                        {
                            UID        = base.Database.Reader["uid"].ToString(),
                            GroupID    = int.Parse(base.Database.Reader["groupid"].ToString()),
                            ServerName = base.Database.Reader["servername"].ToString(),
                            Server     = base.Database.Reader["server"].ToString(),
                            Domain     = base.Database.Reader["domain"].ToString(),
                            Port       = int.Parse(base.Database.Reader["port"].ToString()),
                            Username   = base.Database.Reader["username"].ToString(),

                            Password = (new Func <string>(() =>
                            {
                                string pword = base.Database.Reader["password"].ToString();
                                if (pword != string.Empty)
                                {
                                    pword = RijndaelSettings.Decrypt(pword);
                                }

                                return(pword);
                            }).Invoke()),

                            Description   = base.Database.Reader["description"].ToString(),
                            ColorDepth    = int.Parse(base.Database.Reader["colordepth"].ToString()),
                            DesktopWidth  = int.Parse(base.Database.Reader["desktopwidth"].ToString()),
                            DesktopHeight = int.Parse(base.Database.Reader["desktopheight"].ToString()),
                            Fullscreen    = int.Parse(base.Database.Reader["fullscreen"].ToString()) == 1 ? true : false
                        };

                        this.ArrayListServers.Add(sd);
                    }
                }
            }
            else
            {
                base.Database.CloseConnection();
                System.Diagnostics.Debug.WriteLine(result);
                throw new Exception(result);
            }

            base.Database.CloseConnection();
        }
        void btnStart_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem thisItem in lvRDPFiles.Items)
            {
                thisItem.SubItems[1].Text = "Importing...";

                Model_ServerDetails sd = (Model_ServerDetails)thisItem.Tag;

                try
                {
                    GlobalHelper.dbServers.Save(true, sd);
                }
                catch (Database.DatabaseException settingEx)
                {
                    if (settingEx.ExceptionType == Database.DatabaseException.ExceptionTypes.DUPLICATE_ENTRY)
                    {
                        MessageBox.Show("Can't save '" + sd.ServerName + "' due to duplicate entry", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }

                thisItem.SubItems[1].Text = "Done!";
            }

            foreach (ColumnHeader ch in lvRDPFiles.Columns)
            {
                ch.Width = -1;
            }
        }
        void ssw_ApplySettings(object sender, Model_ServerDetails sd)
        {
            this._sd = sd;

            MessageBox.Show("This will restart your connection", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

            Reconnect(true, false, false);
        }
        public RdpClientWindow(Model_ServerDetails sd, Form parent)
        {
            InitializeComponent();
            InitializeControl(sd);
            InitializeControlEvents();

            this.MdiParent = parent;
            this.Visible   = true;
        }
        // check RemoteDesktopClient_Shown(object sender, EventArgs e)
        void ncm_OnServer_Clicked(object sender, EventArgs e, Model_ServerDetails server_details)
        {
            ListViewItem thisItem = lvServerLists.FindItemWithText(server_details.ServerName, false, 0);

            if (thisItem != null)
            {
                this._selIndex = thisItem.Index;
                this.Connect();
            }
        }
Esempio n. 6
0
 public void Save(bool isNew, Model_ServerDetails server_details)
 {
     if (isNew)
     {
         Save(server_details);
     }
     else
     {
         Update(server_details);
     }
 }
        private void OpenSettingsWindow(object sender, EventArgs e)
        {
            Model_ServerDetails sd = (Model_ServerDetails)lvServerLists.Items[this._selIndex].Tag;

            ServerSettingsWindow ssw = new ServerSettingsWindow(sd);

            ssw.ApplySettings       += new ApplySettings(ssw_ApplySettings);
            ssw.GetClientWindowSize += new GetClientWindowSize(ssw_GetClientWindowSize);
            ssw.ShowDialog();

            GetServerLists();
        }
Esempio n. 8
0
        private void Save(Model_ServerDetails server_details)
        {
            #region sql
            string sql = "INSERT INTO Servers(uid, groupid, servername, server, domain, port, username, password, description, colordepth, desktopwidth, desktopheight, fullscreen) ";
            sql += "VALUES(@uid, @gid, @sname, @server, @domain, @port, @uname, @pword, @desc, @cdepth, @dwidth, @dheight, @fscreen)";
            #endregion

            #region params
            if (server_details.Password != string.Empty)
            {
                server_details.Password = RijndaelSettings.Encrypt(server_details.Password);
            }

            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@uid",     server_details.UID),
                new SQLiteParameter("@gid",     server_details.GroupID),
                new SQLiteParameter("@sname",   server_details.ServerName),
                new SQLiteParameter("@server",  server_details.Server),
                new SQLiteParameter("@domain",  server_details.Domain),
                new SQLiteParameter("@port",    server_details.Port),
                new SQLiteParameter("@uname",   server_details.Username),
                new SQLiteParameter("@pword",   server_details.Password),
                new SQLiteParameter("@desc",    server_details.Description),
                new SQLiteParameter("@cdepth",  server_details.ColorDepth),
                new SQLiteParameter("@dwidth",  server_details.DesktopWidth),
                new SQLiteParameter("@dheight", server_details.DesktopHeight),
                new SQLiteParameter("@fscreen", server_details.Fullscreen)
            };
            #endregion

            string result = base.ExecuteNonQuery(sql, parameters);

            if (result == string.Empty)
            {
            }
            else
            {
                base.Database.CloseConnection();
                System.Diagnostics.Debug.WriteLine(result);

                if (result.Contains("Abort due to constraint violation"))
                {
                    throw new DatabaseException(DatabaseException.ExceptionTypes.DUPLICATE_ENTRY);
                }
                else
                {
                    throw new Exception(result);
                }
            }

            base.Database.CloseConnection();
        }
        void clientWin_ServerSettingsChanged(object sender, Model_ServerDetails sd, int ListIndex)
        {
            ListViewItem item = lvServerLists.Items[ListIndex];

            if (item != null)
            {
                item.Text             = sd.ServerName;
                item.SubItems[1].Text = sd.Server;
                item.SubItems[2].Text = sd.Description;
                item.Tag = sd;
            }
        }
        void btnDelete_Click(object sender, EventArgs e)
        {
            Model_ServerDetails sd = (Model_ServerDetails)lvServerLists.Items[this._selIndex].Tag;

            DialogResult dr = MessageBox.Show("Are you sure you want to delete this server " + sd.ServerName + " from the server list", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr == DialogResult.Yes)
            {
                GlobalHelper.dbServers.DeleteByID(sd.UID);

                GetServerLists();
            }
        }
        void ssw_ApplySettings(object sender, Model_ServerDetails sd)
        {
            RdpClientWindow rdpClientWin = GetClientWindowByTitleParams(sd.Username, sd.ServerName, sd.Server);

            if (rdpClientWin != null)
            {
                rdpClientWin._sd = sd;
                rdpClientWin.Reconnect(true, false, false);
            }
            else
            {
                MessageBox.Show("The relative RDP Client Window for this server does not exists.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        Rectangle ssw_GetClientWindowSize()
        {
            Model_ServerDetails sd           = (Model_ServerDetails)lvServerLists.Items[this._selIndex].Tag;
            RdpClientWindow     rdpClientWin = GetClientWindowByTitleParams(sd.Username, sd.ServerName, sd.Server);

            if (rdpClientWin != null)
            {
                return(rdpClientWin.rdpClient.RectangleToScreen(rdpClientWin.rdpClient.ClientRectangle));
            }
            else
            {
                MessageBox.Show("The relative RDP Client Window for this server does not exists.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Rectangle r = new Rectangle(0, 0, sd.DesktopWidth, sd.DesktopHeight);
                return(r);
            }
        }
        public void InitializeControl(Model_ServerDetails sd)
        {
            GlobalHelper.infoWin.AddControl(new object[] {
                btnFitToScreen
            });

            this._sd = sd;

            rdpClient.Server   = sd.Server;
            rdpClient.UserName = sd.Username;
            //rdpClient.Domain = sd.dom
            rdpClient.AdvancedSettings2.ClearTextPassword = sd.Password;
            rdpClient.ColorDepth    = sd.ColorDepth;
            rdpClient.DesktopWidth  = sd.DesktopWidth;
            rdpClient.DesktopHeight = sd.DesktopHeight;
            rdpClient.FullScreen    = sd.Fullscreen;


            // this fixes the rdp control locking issue
            // when lossing its focus
            //rdpClient.AdvancedSettings3.ContainerHandledFullScreen = -1;
            //rdpClient.AdvancedSettings3.DisplayConnectionBar = true;
            //rdpClient.FullScreen = true;
            //rdpClient.AdvancedSettings3.SmartSizing = true;
            //rdpClient.AdvancedSettings3.PerformanceFlags = 0x00000100;

            //rdpClient.AdvancedSettings2.allowBackgroundInput = -1;
            rdpClient.AdvancedSettings2.AcceleratorPassthrough = -1;
            rdpClient.AdvancedSettings2.Compress          = -1;
            rdpClient.AdvancedSettings2.BitmapPersistence = -1;
            rdpClient.AdvancedSettings2.BitmapPeristence  = -1;
            //rdpClient.AdvancedSettings2.BitmapCacheSize = 512;
            rdpClient.AdvancedSettings2.CachePersistenceActive = -1;


            // custom port
            if (sd.Port != 0)
            {
                rdpClient.AdvancedSettings2.RDPPort = sd.Port;
            }

            btnConnect.Enabled = false;

            panel1.Visible = false;
            tmrSC.Enabled  = false;
        }
Esempio n. 14
0
        public void Connect()
        {
            object x = new object();

            lock (x)
            {
                Model_ServerDetails sd = (Model_ServerDetails)lvServerLists.Items[this._selIndex].Tag;

                bool   canCreateNewForm = true;
                string formTitlePattern = "Remote Desktop Client - {0}@{1}[{2}]";
                string formTitle        = string.Format(formTitlePattern, sd.Username, sd.ServerName, sd.Server);

                foreach (Form f in this.MdiChildren)
                {
                    if (f.Text == formTitle)
                    {
                        f.Activate();
                        canCreateNewForm = false;
                        break;
                    }
                }

                if (canCreateNewForm)
                {
                    RdpClientWindow clientWin = new RdpClientWindow(sd, this);
                    clientWin.Connected             += new Connected(clientWin_Connected);
                    clientWin.Connecting            += new Connecting(clientWin_Connecting);
                    clientWin.LoginComplete         += new LoginComplete(clientWin_LoginComplete);
                    clientWin.Disconnected          += new Disconnected(clientWin_Disconnected);
                    clientWin.OnFormShown           += new OnFormShown(clientWin_OnFormShown);
                    clientWin.OnFormClosing         += new OnFormClosing(clientWin_OnFormClosing);
                    clientWin.OnFormActivated       += new OnFormActivated(clientWin_OnFormActivated);
                    clientWin.ServerSettingsChanged += new ServerSettingsChanged(clientWin_ServerSettingsChanged);
                    clientWin.Text      = formTitle;
                    clientWin.MdiParent = this;
                    System.Diagnostics.Debug.WriteLine(this.Handle);
                    clientWin.ListIndex = this._selIndex;
                    clientWin.Show();
                    clientWin.BringToFront();
                    clientWin.Connect();
                }
            }
        }
Esempio n. 15
0
        void lvServerLists_MouseDown(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo lvhi = lvServerLists.HitTest(new Point(e.X, e.Y));

            if (lvhi.Item != null)
            {
                Model_ServerDetails sd = (Model_ServerDetails)lvhi.Item.Tag;

                status_TextStatus.Text = sd.ServerName + " - " + sd.Server;

                CommonTools.Node n = tlvServerLists.FindNode(sd.ServerName, false);
                if (n != null)
                {
                    tlvServerLists.FocusedNode = n;
                }
            }
            else
            {
                status_TextStatus.Text = string.Empty;
            }
        }
Esempio n. 16
0
        void btnSave_Click(object sender, EventArgs e)
        {
            if (!trw.isAllFieldSet())
            {
                MessageBox.Show("One of the required field is empty", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            int groupId = GlobalHelper.dbGroups.GetIDByGroupName(ddGroup.Text);

            // now force close.. I do not understand why I have to
            // do this twice.
            //GlobalHelper.dbGroups.CloseConnection();
            //GlobalHelper.dbGroups.Database.CloseConnection();

            if (groupId == 0)
            {
                MessageBox.Show("Something went wrong while saving to database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Model_ServerDetails sd = new Model_ServerDetails()
            {
                GroupID       = groupId,
                ServerName    = txServername.Text,
                Server        = txComputer.Text,
                Domain        = txDomain.Text,
                Port          = int.Parse(txPort.Text == string.Empty ? "0" : txPort.Text),
                Username      = txUsername.Text,
                Password      = txPassword.Text,
                Description   = txDescription.Text,
                ColorDepth    = (int)lblColorDepth.Tag,
                DesktopWidth  = int.Parse(txWidth.Text),
                DesktopHeight = int.Parse(txHeight.Text),
                Fullscreen    = cbFullscreen.Checked
            };

            try
            {
                if (this.isUpdating)
                {
                    // pass our old UID to new UID for saving
                    sd.UID = oldSD.UID;

                    GlobalHelper.dbServers.Save(false, sd);
                    if (sd.Password != string.Empty)
                    {
                        sd.Password = RijndaelSettings.Decrypt(sd.Password);
                    }

                    // new settings changed
                    // pass new settings on our oldSD
                    this.oldSD = sd;

                    DialogResult dr = MessageBox.Show("Conection settings successfully updated.\r\nDo you want to apply your current changes.", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dr == DialogResult.Yes)
                    {
                        if (ApplySettings != null)
                        {
                            ApplySettings(sender, this.oldSD);
                        }
                    }

                    this.Close();
                }
                else
                {
                    sd.UID = DateTime.Now.Ticks.ToString();
                    GlobalHelper.dbServers.Save(true, sd);

                    MessageBox.Show("New conenction settings successfully saved", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Database.DatabaseException settingEx)
            {
                if (settingEx.ExceptionType == Database.DatabaseException.ExceptionTypes.DUPLICATE_ENTRY)
                {
                    MessageBox.Show("Can't save your connection settings due to duplicate entry", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
        void ToolbarButtons_Click(object sender, EventArgs e)
        {
            if (sender == btnDisconnect)
            {
                Disconnect();
            }
            else if (sender == btnConnect)
            {
                Connect();
            }
            else if (sender == btnReconnect)
            {
                Reconnect(false, this._isFitToWindow, false);
            }
            else if (sender == btnSettings)
            {
                ServerSettingsWindow ssw = new ServerSettingsWindow(this._sd);

                ssw.ApplySettings       += new ApplySettings(ssw_ApplySettings);
                ssw.GetClientWindowSize += new GetClientWindowSize(ssw_GetClientWindowSize);
                ssw.ShowDialog();

                this._sd = ssw.CurrentServerSettings();

                if (ServerSettingsChanged != null)
                {
                    ServerSettingsChanged(sender, this._sd, this._listIndex);
                }
            }
            else if (sender == btnFullscreen)
            {
                DialogResult dr = MessageBox.Show("You are about to enter in Fullscreen mode.\r\nBy default, the remote desktop resolution will be the same as what you see on the window.\r\n\r\nWould you like to resize it automatically based on your screen resolution though it will be permanent as soon as you leave in Fullscreen.\r\n\r\nNote: This will reconnect.", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dr == DialogResult.Yes)
                {
                    Reconnect(false, false, true);
                }
                else
                {
                    rdpClient.FullScreen = true;
                }
            }
            else if (sender == m_FTS_FitToScreen)
            {
                DialogResult dr = MessageBox.Show("This will resize the server resolution based on this current client window size, though it will not affect you current settings.\r\n\r\nDo you want to continue?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

                if (dr == DialogResult.OK)
                {
                    Reconnect(true, true, false);
                }
            }
            else if (sender == m_FTS_Strech)
            {
                if (int.Parse(m_FTS_Strech.Tag.ToString()) == 0)
                {
                    rdpClient.AdvancedSettings3.SmartSizing = true;
                    m_FTS_Strech.Text = "Don't Stretch";
                    m_FTS_Strech.Tag  = 1;
                }
                else
                {
                    rdpClient.AdvancedSettings3.SmartSizing = false;
                    m_FTS_Strech.Text = "Stretch";
                    m_FTS_Strech.Tag  = 0;
                }
            }
        }
Esempio n. 18
0
 public ServerSettingsWindow(Model_ServerDetails sd)
 {
     InitializeComponent();
     InitializeControls(sd);
     InitializeControlEvents();
 }
Esempio n. 19
0
        void tlvServerLists_MouseDown(object sender, MouseEventArgs e)
        {
            thisSelectedNode = tlvServerLists.CalcHitNode(new Point(e.X, e.Y));

            if (thisSelectedNode != null)
            {
                if (!thisSelectedNode.Key.Contains("gid")) // we don't need parent node / group
                {
                    Model_ServerDetails sd = (Model_ServerDetails)thisSelectedNode.Tag;
                    status_TextStatus.Text = sd.ServerName + " - " + sd.Server;
                    this.tlvch.EnableControls(true);

                    ListViewItem thisItem = this.lvServerLists.FindItemWithText(thisSelectedNode[0].ToString());

                    if (thisItem != null)
                    {
                        // select the item on our listview too
                        thisItem.Selected = true;
                    }
                }
                else
                {
                    // disable all unnecessary controls
                    this.tlvch.EnableControls(false);

                    // ok .. we like our ConnectAll button and Menu strip item to be enabled
                    // so we can use it when we selected our parent node / group
                    // let's just enable them
                    toolbar_ConnectAll.Enabled = true;
                    lvServerListsContextMenu_ConnectAll.Enabled = true;

                    // and we have to let our "this._selIndex" at least know
                    // where to start so when we click ConnectAll in a parent node,
                    // it has a way to check.

                    // say the first item in a listview group.
                    // remeber, we are basing our events on listview instead of the treeview
                    // to prevent confusion

                    //if (thisSelectedNode.HasChildren)
                    if (thisSelectedNode.Nodes.Count != 0)
                    {
                        // get the first child node
                        CommonTools.Node n = thisSelectedNode.Nodes.FirstNode;

                        // and match that in our listview
                        ListViewItem item = lvServerLists.FindItemWithText(n[0].ToString(), false, 0, true);
                        if (item != null)
                        {
                            // ok so we have it.
                            this._selIndex = item.Index;
                        }

                        item = null;
                        n    = null;
                    }
                    else
                    {
                        // no child nodes
                        // let's just disable ConnectAll buttons and menu items again
                        // disable all unnecessary controls
                        this.tlvch.EnableControls(false);
                    }
                }
            }
            else
            {
                // disable all unnecessary controls
                // if nothing is selected
                this.tlvch.EnableControls(false);
            }
        }
Esempio n. 20
0
        public void InitializeControls(Model_ServerDetails sd)
        {
            this.oldSD = sd;

            trw.AddRange(new Control[] {
                txServername,
                txComputer,
                txUsername,
                txDescription
            });

            txServername.Text  = sd.ServerName;
            txComputer.Text    = sd.Server;
            txDomain.Text      = sd.Domain;
            txPort.Text        = sd.Port.ToString();
            txUsername.Text    = sd.Username;
            txPassword.Text    = sd.Password;
            txDescription.Text = sd.Description;

            switch (sd.ColorDepth)
            {
            case 24:
                tbColor.Value = 1;
                break;

            case 16:
                tbColor.Value = 2;
                break;

            case 15:
                tbColor.Value = 3;
                break;

            case 8:
                tbColor.Value = 4;
                break;
            }
            tbColor_Scroll(tbColor, null);

            if (sd.DesktopWidth == 640 && sd.DesktopHeight == 480)
            {
                tbDeskSize.Value = 1;
            }
            else if (sd.DesktopWidth == 800 && sd.DesktopHeight == 600)
            {
                tbDeskSize.Value = 2;
            }
            else if (sd.DesktopWidth == 1024 && sd.DesktopHeight == 768)
            {
                tbDeskSize.Value = 3;
            }
            else if (sd.DesktopWidth == 1120 && sd.DesktopHeight == 700)
            {
                tbDeskSize.Value = 4;
            }
            else if (sd.DesktopWidth == 1152 && sd.DesktopHeight == 864)
            {
                tbDeskSize.Value = 5;
            }
            else if (sd.DesktopWidth == 1280 && sd.DesktopHeight == 800)
            {
                tbDeskSize.Value = 6;
            }
            else if (sd.DesktopWidth == 1280 && sd.DesktopHeight == 1024)
            {
                tbDeskSize.Value = 7;
            }
            tbColor_Scroll(tbColor, null);

            txWidth.Text         = sd.DesktopWidth.ToString();
            txHeight.Text        = sd.DesktopHeight.ToString();
            cbFullscreen.Checked = sd.Fullscreen;

            this.isUpdating = true;

            GlobalHelper.PopulateGroupsDropDown(ddGroup, GlobalHelper.dbGroups.GetGroupNameByID(sd.GroupID));

            btnGetClientWinS.Enabled = true;
        }
Esempio n. 21
0
        void btnStart_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.ShowDialog();

            if (fbd.SelectedPath != string.Empty)
            {
                foreach (ListViewItem thisItem in lvRDPFiles.Items)
                {
                    if (thisItem.Checked == true)
                    {
                        thisItem.SubItems[1].Text = "Importing...";

                        Model_ServerDetails sd = (Model_ServerDetails)thisItem.Tag;

                        RDPFile rdp = new RDPFile();
                        rdp.ScreenMode    = 1;
                        rdp.DesktopWidth  = sd.DesktopWidth;
                        rdp.DesktopHeight = sd.DesktopHeight;
                        rdp.SessionBPP    = (RDPFile.SessionBPPs)sd.ColorDepth;

                        RDPFile.WindowsPosition winpos = new RDPFile.WindowsPosition();
                        RDPFile.RECT            r      = new RDPFile.RECT();
                        r.Top           = 0;
                        r.Left          = 0;
                        r.Width         = sd.DesktopWidth;
                        r.Height        = sd.DesktopHeight;
                        winpos.Rect     = r;
                        winpos.WinState = RDPFile.WindowState.MAXMIZE;

                        rdp.WinPosStr               = winpos;
                        rdp.FullAddress             = sd.Server;
                        rdp.Compression             = 1;
                        rdp.KeyboardHook            = RDPFile.KeyboardHooks.ON_THE_REMOTE_COMPUTER;
                        rdp.AudioMode               = RDPFile.AudioModes.BRING_TO_THIS_COMPUTER;
                        rdp.RedirectDrives          = 0;
                        rdp.RedirectPrinters        = 0;
                        rdp.RedirectComPorts        = 0;
                        rdp.RedirectSmartCards      = 0;
                        rdp.DisplayConnectionBar    = 1;
                        rdp.AutoReconnectionEnabled = 1;
                        rdp.Username              = sd.Username;
                        rdp.Domain                = string.Empty;
                        rdp.AlternateShell        = string.Empty;
                        rdp.ShellWorkingDirectory = string.Empty;

                        // what's with the ZERO ?
                        // http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/
                        rdp.Password = (sd.Password == string.Empty ? string.Empty : DataProtectionForRDPWrapper.Encrypt(sd.Password) + "0");

                        //System.Diagnostics.Debug.WriteLine(ss.Password);
                        rdp.DisableWallpaper         = 1;
                        rdp.DisableFullWindowDrag    = 1;
                        rdp.DisableMenuAnims         = 1;
                        rdp.DisableThemes            = 1;
                        rdp.DisableCursorSettings    = 1;
                        rdp.BitmapCachePersistEnable = 1;

                        #region try exporting the file
                        {
                            try
                            {
                                rdp.Save(Path.Combine(fbd.SelectedPath, sd.ServerName + ".rdp"));

                                thisItem.SubItems[1].Text = "Done!";
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("An error occured while exporting the server '" + sd.ServerName + "' to RDP file format.\r\n\r\nError Message: " + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                System.Diagnostics.Debug.WriteLine(ex.Message + "\r\n" + ex.StackTrace);

                                continue;
                            }
                        }
                        #endregion
                    }
                }
            }
        }
Esempio n. 22
0
        void btnBrowse_Click(object sender, EventArgs e)
        {
            ofd             = new OpenFileDialog();
            ofd.Filter      = "RDP File|*.rdp";
            ofd.Multiselect = true;
            ofd.Title       = "Import RDP File";
            ofd.ShowDialog();

            foreach (string thisFile in ofd.FileNames)
            {
                System.Diagnostics.Debug.WriteLine("reading " + thisFile);

                #region Read RDP File

                RDPFile rdpfile;
                {
                    try
                    {
                        rdpfile = new RDPFile();
                        rdpfile.Read(thisFile);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("An error occured while reading '" + Path.GetFileName(thisFile) + "' and it will be skipped.\r\n\r\nError Message: " + ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        System.Diagnostics.Debug.WriteLine(ex.Message + "\r\n" + ex.StackTrace);

                        continue;
                    }
                }
                #endregion

                Model_ServerDetails sd = new Model_ServerDetails();
                sd.UID        = DateTime.Now.Ticks.ToString();
                sd.GroupID    = 1;
                sd.ServerName = System.IO.Path.GetFileNameWithoutExtension(thisFile);
                sd.Server     = rdpfile.FullAddress;
                sd.Username   = rdpfile.Username;

                #region Try decrypting the password from RDP file
                {
                    try
                    {
                        System.Diagnostics.Debug.WriteLine("reading password " + thisFile);

                        string RDPPassword = rdpfile.Password;
                        if (RDPPassword != string.Empty)
                        {
                            // based on http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/
                            // he saids, MSTSC just add a ZERO number at the end of the hashed password.
                            // so let's just removed THAT!
                            RDPPassword = RDPPassword.Substring(0, RDPPassword.Length - 1);
                            // and decrypt it!
                            RDPPassword = DataProtection.DataProtectionForRDPWrapper.Decrypt(RDPPassword);

                            sd.Password = RDPPassword;
                        }

                        System.Diagnostics.Debug.WriteLine("reading password done");
                    }
                    catch (Exception Ex)
                    {
                        sd.Password = string.Empty;

                        if (Ex.Message == "Problem converting Hex to Bytes")
                        {
                            MessageBox.Show("This RDP File '" + Path.GetFileNameWithoutExtension(thisFile) + "' contains a secured password which is currently unsported by this application.\r\nThe importing can still continue but without the password.\r\nYou can edit the password later by selecting a server in 'All Listed Servers' and click 'Edit Settings' button on the toolbar", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        else if (Ex.Message.Contains("Exception decrypting"))
                        {
                            MessageBox.Show("Failed to decrypt the password from '" + Path.GetFileNameWithoutExtension(thisFile) + "'", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            MessageBox.Show("An unknown error occured while decrypting the password from '" + Path.GetFileNameWithoutExtension(thisFile) + "'", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                #endregion

                sd.Description   = "Imported from " + thisFile;
                sd.ColorDepth    = (int)rdpfile.SessionBPP;
                sd.DesktopWidth  = rdpfile.DesktopWidth;
                sd.DesktopHeight = rdpfile.DesktopHeight;
                sd.Fullscreen    = false;

                ListViewItem thisItem = new ListViewItem(Path.GetFileNameWithoutExtension(thisFile));
                thisItem.SubItems.Add("OK");
                thisItem.SubItems.Add(thisFile);
                thisItem.Tag        = sd;
                thisItem.ImageIndex = 0;

                lvRDPFiles.Items.Add(thisItem);
            }

            foreach (ColumnHeader ch in lvRDPFiles.Columns)
            {
                ch.Width = -1;
            }
        }