Example #1
0
        private 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, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        System.Diagnostics.Debug.WriteLine(ex.Message + "\r\n" + ex.StackTrace);

                        continue;
                    }
                }

                #endregion

                ServerDetails sd = new ServerDetails();
                //TODO: Find out what this group id 1 is
                //sd.GroupID = 1;
                sd.ServerName = Path.GetFileNameWithoutExtension(thisFile);
                sd.Server     = rdpfile.FullAddress ?? sd.ServerName;
                sd.Username   = rdpfile.Username;

                #region Try decrypting the password from RDP file

                try
                {
                    System.Diagnostics.Debug.WriteLine("reading password " + thisFile);

                    string password = rdpfile.Password;
                    sd.Password = Password.Empty;
                    if (!string.IsNullOrEmpty(password))
                    {
                        // 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!
                        password = password.Substring(0, password.Length - 1);
                        // and decrypt it!
                        password    = DataProtectionForRDPWrapper.Decrypt(password);
                        sd.Password = new Password(password, false);
                    }

                    System.Diagnostics.Debug.WriteLine("reading password done");
                }
                catch (Exception Ex)
                {
                    sd.Password = Password.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", Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else if (Ex.Message.Contains("Exception decrypting"))
                    {
                        MessageBox.Show("Failed to decrypt the password from '" + Path.GetFileNameWithoutExtension(thisFile) + "'", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("An unknown error occured while decrypting the password from '" + Path.GetFileNameWithoutExtension(thisFile) + "'", 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;
            }
        }
Example #2
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...";

                        Database.ServerDetails sd = (Database.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
                    }
                }
            }
        }
Example #3
0
 private void btnDecrypt_Click(object sender, EventArgs e)
 {
     txPassword.Text = DataProtectionForRDPWrapper.Decrypt(txHash.Text);
 }