private void FillFavoriteRdpTimeOutOptions(RdpOptions rdpOptions)
 {
     rdpOptions.TimeOuts.ShutdownTimeout = ParseInteger(this.ShutdownTimeoutTextBox);
     rdpOptions.TimeOuts.OverallTimeout = ParseInteger(this.OverallTimeoutTextbox);
     rdpOptions.TimeOuts.ConnectionTimeout = ParseInteger(this.SingleTimeOutTextbox);
     rdpOptions.TimeOuts.IdleTimeout = ParseInteger(this.IdleTimeoutMinutesTextBox);
 }
        private void FillFavoriteTSgatewayOptions(RdpOptions rdpOptions)
        {
            this.credentialsPanel1.SaveMRUs();
            TsGwOptions tsgwOptions = rdpOptions.TsGateway;
            tsgwOptions.HostName = this.txtTSGWServer.Text;
            this.credentialsPanel1.SaveTo(tsgwOptions.Security);
            tsgwOptions.SeparateLogin = this.chkTSGWlogin.Checked;
            tsgwOptions.CredentialSource = this.cmbTSGWLogonMethod.SelectedIndex;
            if (tsgwOptions.CredentialSource == 2)
                tsgwOptions.CredentialSource = 4;

            if (this.radTSGWenable.Checked)
            {
                if (this.chkTSGWlocalBypass.Checked)
                    tsgwOptions.UsageMethod = 2;
                else
                    tsgwOptions.UsageMethod = 1;
            }
            else
            {
                if (this.chkTSGWlocalBypass.Checked)
                    tsgwOptions.UsageMethod = 4;
                else
                    tsgwOptions.UsageMethod = 0;
            }
        }
 private void FillRdpTimeOutControls(RdpOptions rdpOptions)
 {
     this.ShutdownTimeoutTextBox.Text = rdpOptions.TimeOuts.ShutdownTimeout.ToString(CultureInfo.InvariantCulture);
     this.OverallTimeoutTextbox.Text = rdpOptions.TimeOuts.OverallTimeout.ToString(CultureInfo.InvariantCulture);
     this.SingleTimeOutTextbox.Text = rdpOptions.TimeOuts.ConnectionTimeout.ToString(CultureInfo.InvariantCulture);
     this.IdleTimeoutMinutesTextBox.Text = rdpOptions.TimeOuts.IdleTimeout.ToString(CultureInfo.InvariantCulture);
 }
 private void FillRdpDisplayControls(RdpOptions rdpOptions)
 {
     var userInterface = rdpOptions.UserInterface;
     this.chkDisableWallpaper.Checked = userInterface.DisableWallPaper;
     this.chkDisableCursorBlinking.Checked = userInterface.DisableCursorBlinking;
     this.chkDisableCursorShadow.Checked = userInterface.DisableCursorShadow;
     this.chkDisableFullWindowDrag.Checked = userInterface.DisableFullWindowDrag;
     this.chkDisableMenuAnimations.Checked = userInterface.DisableMenuAnimations;
     this.chkDisableThemes.Checked = userInterface.DisableTheming;
     this.AllowFontSmoothingCheckbox.Checked = userInterface.EnableFontSmoothing;
     this.AllowDesktopCompositionCheckbox.Checked = userInterface.EnableDesktopComposition;
 }
 private void FillFavoriteRdpDisplayOptions(RdpOptions rdpOptions)
 {
     var userInterface = rdpOptions.UserInterface;
     userInterface.DisableWallPaper = this.chkDisableWallpaper.Checked;
     userInterface.DisableCursorBlinking = this.chkDisableCursorBlinking.Checked;
     userInterface.DisableCursorShadow = this.chkDisableCursorShadow.Checked;
     userInterface.DisableFullWindowDrag = this.chkDisableFullWindowDrag.Checked;
     userInterface.DisableMenuAnimations = this.chkDisableMenuAnimations.Checked;
     userInterface.DisableTheming = this.chkDisableThemes.Checked;
     userInterface.EnableFontSmoothing = this.AllowFontSmoothingCheckbox.Checked;
     userInterface.EnableDesktopComposition = this.AllowDesktopCompositionCheckbox.Checked;
 }
 private void FillFavoriteRdpInterfaceOptions(RdpOptions rdpOptions)
 {
     RdpUserInterfaceOptions userInterface = rdpOptions.UserInterface;
     rdpOptions.GrabFocusOnConnect = this.GrabFocusOnConnectCheckbox.Checked;
     userInterface.DisableWindowsKey = this.DisableWindowsKeyCheckbox.Checked;
     userInterface.DoubleClickDetect = this.DetectDoubleClicksCheckbox.Checked;
     userInterface.DisplayConnectionBar = this.DisplayConnectionBarCheckbox.Checked;
     userInterface.DisableControlAltDelete = this.DisableControlAltDeleteCheckbox.Checked;
     userInterface.AcceleratorPassthrough = this.AcceleratorPassthroughCheckBox.Checked;
     userInterface.EnableCompression = this.EnableCompressionCheckbox.Checked;
     userInterface.BitmapPeristence = this.EnableBitmapPersistenceCheckbox.Checked;
     userInterface.AllowBackgroundInput = this.AllowBackgroundInputCheckBox.Checked;
     userInterface.LoadBalanceInfo = this.txtLoadBalanceInfo.Text;
 }
        private void FillTsGatewayControls(RdpOptions rdpOptions)
        {
            this.credentialsPanel1.LoadMRUs();
            TsGwOptions tsGateway = rdpOptions.TsGateway;

            switch (tsGateway.UsageMethod)
            {
                case 0:
                    this.radTSGWdisable.Checked = true;
                    this.chkTSGWlocalBypass.Checked = false;
                    break;
                case 1:
                    this.radTSGWenable.Checked = true;
                    this.chkTSGWlocalBypass.Checked = false;
                    break;
                case 2:
                    this.radTSGWenable.Checked = true;
                    this.chkTSGWlocalBypass.Checked = true;
                    break;
                case 4:
                    this.radTSGWdisable.Checked = true;
                    this.chkTSGWlocalBypass.Checked = true;
                    break;
            }

            this.txtTSGWServer.Text = tsGateway.HostName;
            this.chkTSGWlogin.Checked = tsGateway.SeparateLogin;
            this.credentialsPanel1.Enabled = tsGateway.SeparateLogin;

            if (tsGateway.SeparateLogin)
                this.credentialsPanel1.LoadFrom(tsGateway.Security);

            if (tsGateway.CredentialSource == 4)
                this.cmbTSGWLogonMethod.SelectedIndex = 2;
            else
                this.cmbTSGWLogonMethod.SelectedIndex = tsGateway.CredentialSource;
        }
        private void ConfigureStartBehaviour(RdpOptions rdpOptions)
        {
            if (rdpOptions.GrabFocusOnConnect)
                this.client.AdvancedSettings2.GrabFocusOnConnect = true;

            if (rdpOptions.Security.Enabled)
            {
                if (rdpOptions.FullScreen)
                    this.client.SecuredSettings2.FullScreen = -1;

                this.client.SecuredSettings2.StartProgram = rdpOptions.Security.StartProgram;
                this.client.SecuredSettings2.WorkDir = rdpOptions.Security.WorkingFolder;
            }
        }
        private void ConfigureSecurity(RdpOptions rdpOptions)
        {
            if (rdpOptions.Security.EnableTLSAuthentication)
                this.client.AdvancedSettings5.AuthenticationLevel = 2;

            this.nonScriptable.EnableCredSspSupport = rdpOptions.Security.EnableNLAAuthentication;

            var audioMode = (int)rdpOptions.Redirect.Sounds;
            this.client.SecuredSettings2.AudioRedirectionMode = (audioMode >= 0 && audioMode <= 2) ? audioMode : 0;

            ISecurityOptions security = this.Favorite.Security.GetResolvedCredentials();

            this.client.UserName = security.UserName;
            this.client.Domain = security.Domain;
            try
            {
                if (!String.IsNullOrEmpty(security.Password))
                {
                    if (this.nonScriptable != null)
                        this.nonScriptable.ClearTextPassword = security.Password;
                }
            }
            catch (Exception exc)
            {
                Logging.Error("Error when trying to set the ClearTextPassword on the nonScriptable mstsc object", exc);
            }
        }
 private void ConfigureRedirectOptions(RdpOptions rdpOptions)
 {
     this.client.AdvancedSettings3.RedirectPorts = rdpOptions.Redirect.Ports;
     this.client.AdvancedSettings3.RedirectPrinters = rdpOptions.Redirect.Printers;
     this.client.AdvancedSettings3.RedirectSmartCards = rdpOptions.Redirect.SmartCards;
     this.client.AdvancedSettings3.PerformanceFlags = rdpOptions.UserInterface.PerformanceFlags;
     this.client.AdvancedSettings6.RedirectClipboard = rdpOptions.Redirect.Clipboard;
     this.client.AdvancedSettings6.RedirectDevices = rdpOptions.Redirect.Devices;
 }
 private void ConfigureRedirectedDrives(RdpOptions rdpOptions)
 {
     if (rdpOptions.Redirect.Drives.Count > 0 && rdpOptions.Redirect.Drives[0].Equals("true"))
         this.client.AdvancedSettings2.RedirectDrives = true;
     else
     {
         for (int i = 0; i < nonScriptable.DriveCollection.DriveCount; i++)
         {
             MSTSCLib.IMsRdpDrive drive = nonScriptable.DriveCollection.get_DriveByIndex((uint)i);
             foreach (string str in rdpOptions.Redirect.Drives)
             {
                 if (drive.Name.IndexOf(str) > -1)
                     drive.RedirectionState = true;
             }
         }
     }
 }
        private void ConfigureInterface(RdpOptions rdpOptions)
        {
            //advanced settings
            //bool, 0 is false, other is true
            if (rdpOptions.UserInterface.AllowBackgroundInput)
                this.client.AdvancedSettings.allowBackgroundInput = -1;

            if (rdpOptions.UserInterface.BitmapPeristence)
                this.client.AdvancedSettings.BitmapPeristence = -1;

            if (rdpOptions.UserInterface.EnableCompression)
                this.client.AdvancedSettings.Compress = -1;

            if (rdpOptions.UserInterface.AcceleratorPassthrough)
                this.client.AdvancedSettings2.AcceleratorPassthrough = -1;

            if (rdpOptions.UserInterface.DisableControlAltDelete)
                this.client.AdvancedSettings2.DisableCtrlAltDel = -1;

            if (rdpOptions.UserInterface.DisplayConnectionBar)
                this.client.AdvancedSettings2.DisplayConnectionBar = true;

            if (rdpOptions.UserInterface.DoubleClickDetect)
                this.client.AdvancedSettings2.DoubleClickDetect = -1;

            if (rdpOptions.UserInterface.DisableWindowsKey)
                this.client.AdvancedSettings2.EnableWindowsKey = -1;

            if (rdpOptions.Security.EnableEncryption)
                this.client.AdvancedSettings2.EncryptionEnabled = -1;

            this.ConfigureAzureService(rdpOptions);
            this.ConfigureCustomReconnect();
        }
 private void ConfigureConnectionBar(RdpOptions rdpOptions)
 {
     this.client.AdvancedSettings6.ConnectionBarShowMinimizeButton = false;
     this.client.AdvancedSettings6.ConnectionBarShowPinButton = false;
     this.client.AdvancedSettings6.ConnectionBarShowRestoreButton = false;
     this.client.AdvancedSettings3.DisplayConnectionBar = rdpOptions.UserInterface.DisplayConnectionBar;
 }
        /// <summary>
        /// The ActiveX component requires a UTF-8 encoded string, but .NET uses
        /// UTF-16 encoded strings by default.  The following code converts
        /// the UTF-16 encoded string so that the byte-representation of the
        /// LoadBalanceInfo string object will "appear" as UTF-8 to the Active component.
        /// Furthermore, since the final string still has to be shoehorned into
        /// a UTF-16 encoded string, I pad an extra space in case the number of
        /// bytes would be odd, in order to prevent the byte conversion from
        /// mangling the string at the end.  The space is ignored by the RDP
        /// protocol as long as it is inserted at the end.
        /// Finally, it is required that the LoadBalanceInfo setting is postfixed
        /// with \r\n in order to work properly.  Note also that \r\n MUST be
        /// the last two characters, so the space padding has to be inserted first.
        /// The following code has been tested with Windows Azure connections
        /// only - I am aware there are other types of RDP connections that
        /// require the LoadBalanceInfo parameter which I have not tested
        /// (e.g., Multi-Server Terminal Services Gateway), that may or may not
        /// work properly.
        ///
        /// Sources:
        ///  1. http://stackoverflow.com/questions/13536267/how-to-connect-to-azure-vm-with-remote-desktop-activex
        ///  2. http://social.technet.microsoft.com/Forums/windowsserver/en-US/e68d4e9a-1c8a-4e55-83b3-e3b726ff5346/issue-with-using-advancedsettings2loadbalanceinfo
        ///  3. Manual comparison of raw packets between Windows RDP client and Terminals using WireShark.
        /// </summary>
        private void ConfigureAzureService(RdpOptions rdpOptions)
        {
            if (!string.IsNullOrEmpty(rdpOptions.UserInterface.LoadBalanceInfo))
            {
                var lbTemp = rdpOptions.UserInterface.LoadBalanceInfo;

                if (lbTemp.Length % 2 == 1)
                    lbTemp += " ";

                lbTemp += "\r\n";
                byte[] bytes = Encoding.UTF8.GetBytes(lbTemp);
                string lbFinal = Encoding.Unicode.GetString(bytes);
                this.client.AdvancedSettings2.LoadBalanceInfo = lbFinal;
            }
        }
 private void FillRdpUserInterfaceControls(RdpOptions rdpOptions)
 {
     var userInterface = rdpOptions.UserInterface;
     this.GrabFocusOnConnectCheckbox.Checked = rdpOptions.GrabFocusOnConnect;
     this.DisableWindowsKeyCheckbox.Checked = userInterface.DisableWindowsKey;
     this.DetectDoubleClicksCheckbox.Checked = userInterface.DoubleClickDetect;
     this.DisplayConnectionBarCheckbox.Checked = userInterface.DisplayConnectionBar;
     this.DisableControlAltDeleteCheckbox.Checked = userInterface.DisableControlAltDelete;
     this.AcceleratorPassthroughCheckBox.Checked = userInterface.AcceleratorPassthrough;
     this.EnableCompressionCheckbox.Checked = userInterface.EnableCompression;
     this.EnableBitmapPersistenceCheckbox.Checked = userInterface.BitmapPeristence;
     this.AllowBackgroundInputCheckBox.Checked = userInterface.AllowBackgroundInput;
     this.txtLoadBalanceInfo.Text = userInterface.LoadBalanceInfo;
 }
        private void ConfigureTimeouts(RdpOptions rdpOptions)
        {
            try
            {
                this.client.AdvancedSettings2.MinutesToIdleTimeout = rdpOptions.TimeOuts.IdleTimeout;

                int timeout = rdpOptions.TimeOuts.OverallTimeout;
                if (timeout > 600)
                    timeout = 10;
                if (timeout <= 0)
                    timeout = 10;
                this.client.AdvancedSettings2.overallConnectionTimeout = timeout;
                timeout = rdpOptions.TimeOuts.ConnectionTimeout;
                if (timeout > 600)
                    timeout = 10;
                if (timeout <= 0)
                    timeout = 10;

                this.client.AdvancedSettings2.singleConnectionTimeout = timeout;

                timeout = rdpOptions.TimeOuts.ShutdownTimeout;
                if (timeout > 600)
                    timeout = 10;
                if (timeout <= 0)
                    timeout = 10;
                this.client.AdvancedSettings2.shutdownTimeout = timeout;
            }
            catch (Exception exc)
            {
                Logging.Error("Error when trying to set timeout values.", exc);
            }
        }
 private void ConfigureTsGateway(RdpOptions rdpOptions)
 {
     // Terminal Server Gateway Settings
     this.client.TransportSettings.GatewayUsageMethod = (uint)rdpOptions.TsGateway.UsageMethod;
     this.client.TransportSettings.GatewayCredsSource = (uint)rdpOptions.TsGateway.CredentialSource;
     this.client.TransportSettings.GatewayHostname = rdpOptions.TsGateway.HostName;
     this.client.TransportSettings2.GatewayDomain = rdpOptions.TsGateway.Security.Domain;
     this.client.TransportSettings2.GatewayProfileUsageMethod = 1;
     if (rdpOptions.TsGateway.SeparateLogin)
     {
         this.client.TransportSettings2.GatewayUsername = rdpOptions.TsGateway.Security.UserName;
         this.client.TransportSettings2.GatewayPassword = rdpOptions.TsGateway.Security.Password;
     }
     else
     {
         this.client.TransportSettings2.GatewayUsername = this.Favorite.Security.UserName;
         this.client.TransportSettings2.GatewayPassword = this.Favorite.Security.Password;
     }
 }
 private void ConfigureConnection(RdpOptions rdpOptions)
 {
     this.client.Server = this.Favorite.ServerName;
     this.client.AdvancedSettings3.RDPPort = this.Favorite.Port;
     this.client.AdvancedSettings3.ContainerHandledFullScreen = -1;
     // Use ConnectToServerConsole or ConnectToAdministerServer based on implementation
     this.client.AdvancedSettings7.ConnectToAdministerServer = rdpOptions.ConnectToConsole;
     this.client.AdvancedSettings3.ConnectToServerConsole = rdpOptions.ConnectToConsole;
 }