public override bool Connect() { try { axMsRdpClient2 = new AxMsRdpClient2(); Controls.Add(axMsRdpClient2); axMsRdpClient2.BringToFront(); this.BringToFront(); axMsRdpClient2.Parent = base.TerminalTabPage; this.Parent = TerminalTabPage; axMsRdpClient2.AllowDrop = true; ((Control)axMsRdpClient2).DragEnter += new DragEventHandler(axMsRdpClient2_DragEnter); ((Control)axMsRdpClient2).DragDrop += new DragEventHandler(axMsRdpClient2_DragDrop); axMsRdpClient2.OnConnected += new EventHandler(axMsRdpClient2_OnConnected); axMsRdpClient2.Dock = DockStyle.Fill; ChangeDesktopSize(Favorite.DesktopSize); try { //if(Favorite.DesktopSize == DesktopSize.AutoScale) axMsRdpClient2.AdvancedSettings3.SmartSizing = true; //axMsRdpClient2.DesktopWidth = width; //axMsRdpClient2.DesktopHeight = height; switch(Favorite.Colors) { case Colors.Bits8: axMsRdpClient2.ColorDepth = 8; break; case Colors.Bit16: axMsRdpClient2.ColorDepth = 16; break; case Colors.Bits24: axMsRdpClient2.ColorDepth = 24; break; case Colors.Bits32: if(Settings.SupportsRDP6) axMsRdpClient2.ColorDepth = 32; else axMsRdpClient2.ColorDepth = 24; break; } axMsRdpClient2.ConnectingText = "Connecting. Please wait..."; axMsRdpClient2.DisconnectedText = "Disconnecting..."; axMsRdpClient2.AdvancedSettings3.RedirectDrives = Favorite.RedirectDrives; //advanced settings //bool, 0 is false, other is true if(Favorite.AllowBackgroundInput) axMsRdpClient2.AdvancedSettings.allowBackgroundInput = -1; if(Favorite.BitmapPeristence) axMsRdpClient2.AdvancedSettings.BitmapPeristence = -1; if(Favorite.EnableCompression) axMsRdpClient2.AdvancedSettings.Compress = -1; if(Favorite.AcceleratorPassthrough) axMsRdpClient2.AdvancedSettings2.AcceleratorPassthrough = -1; if(Favorite.DisableControlAltDelete) axMsRdpClient2.AdvancedSettings2.DisableCtrlAltDel = -1; if(Favorite.DisplayConnectionBar) axMsRdpClient2.AdvancedSettings2.DisplayConnectionBar = true; if(Favorite.DoubleClickDetect) axMsRdpClient2.AdvancedSettings2.DoubleClickDetect = -1; if(Favorite.DisableWindowsKey) axMsRdpClient2.AdvancedSettings2.EnableWindowsKey = -1; if(Favorite.EnableEncryption) axMsRdpClient2.AdvancedSettings2.EncryptionEnabled = -1; if(Favorite.GrabFocusOnConnect) axMsRdpClient2.AdvancedSettings2.GrabFocusOnConnect = true; if(Favorite.EnableSecuritySettings) { if(Favorite.SecurityFullScreen) axMsRdpClient2.SecuredSettings2.FullScreen = -1; axMsRdpClient2.SecuredSettings2.StartProgram = Favorite.SecurityStartProgram; axMsRdpClient2.SecuredSettings2.WorkDir = Favorite.SecurityWorkingFolder; } axMsRdpClient2.AdvancedSettings2.MinutesToIdleTimeout = Favorite.IdleTimeout; try { int timeout = Favorite.OverallTimeout; if(timeout > 600) timeout = 10; if(timeout <= 0) timeout = 10; axMsRdpClient2.AdvancedSettings2.overallConnectionTimeout = timeout; timeout = Favorite.ConnectionTimeout; if(timeout > 600) timeout = 10; if(timeout <= 0) timeout = 10; axMsRdpClient2.AdvancedSettings2.singleConnectionTimeout = timeout; timeout = Favorite.ShutdownTimeout; if(timeout > 600) timeout = 10; if(timeout <= 0) timeout = 10; axMsRdpClient2.AdvancedSettings2.shutdownTimeout = timeout; //axMsRdpClient2.AdvancedSettings2.PinConnectionBar; //axMsRdpClient2.AdvancedSettings2.TransportType; //axMsRdpClient2.AdvancedSettings2.WinceFixedPalette; //axMsRdpClient2.AdvancedSettings3.CanAutoReconnect = Favorite.CanAutoReconnect; } catch(Exception exc) { Terminals.Logging.Log.Error("Error when trying to set timeout values.", exc); } axMsRdpClient2.AdvancedSettings3.RedirectPorts = Favorite.RedirectPorts; axMsRdpClient2.AdvancedSettings3.RedirectPrinters = Favorite.RedirectPrinters; axMsRdpClient2.AdvancedSettings3.RedirectSmartCards = Favorite.RedirectSmartCards; axMsRdpClient2.AdvancedSettings3.PerformanceFlags = Favorite.PerformanceFlags; /* TS_PERF_DISABLE_CURSOR_SHADOW 0x00000020 No shadow is displayed for the cursor. TS_PERF_DISABLE_CURSORSETTINGS 0x00000040 Cursor blinking is disabled. TS_PERF_DISABLE_FULLWINDOWDRAG 0x00000002 Full-window drag is disabled; only the window outline is displayed when the window is moved. TS_PERF_DISABLE_MENUANIMATIONS 0x00000004 Menu animations are disabled. TS_PERF_DISABLE_NOTHING 0x00000000 No features are disabled. TS_PERF_DISABLE_THEMING 0x00000008 Themes are disabled. TS_PERF_DISABLE_WALLPAPER 0x00000001 Wallpaper on the desktop is not displayed. */ if(Settings.SupportsRDP6) { MSTSCLib6.IMsRdpClientAdvancedSettings5 advancedSettings5 = (axMsRdpClient2.AdvancedSettings3 as MSTSCLib6.IMsRdpClientAdvancedSettings5); if(advancedSettings5 != null) { advancedSettings5.RedirectClipboard = Favorite.RedirectClipboard; advancedSettings5.RedirectDevices = Favorite.RedirectDevices; advancedSettings5.ConnectionBarShowMinimizeButton = false; advancedSettings5.ConnectionBarShowPinButton = false; advancedSettings5.ConnectionBarShowRestoreButton = false; } } axMsRdpClient2.SecuredSettings2.AudioRedirectionMode = (int)Favorite.Sounds; string domainName = Favorite.DomainName; if(domainName == null || domainName == "") domainName = Settings.DefaultDomain; string pass = Favorite.Password; if(pass == null || pass == "") pass = Settings.DefaultPassword; string userName = Favorite.UserName; if(userName == null || userName == "") userName = Settings.DefaultUsername; axMsRdpClient2.UserName = userName; axMsRdpClient2.Domain = domainName; try { if(!String.IsNullOrEmpty(pass)) { MSTSC.IMsTscNonScriptable nonScriptable = (MSTSC.IMsTscNonScriptable)axMsRdpClient2.GetOcx(); if(nonScriptable!=null) nonScriptable.ClearTextPassword = pass; } } catch(Exception exc) { Terminals.Logging.Log.Error("Error when trying to set the ClearTextPassword on the nonScriptable mstsc object", exc); } axMsRdpClient2.Server = Favorite.ServerName; axMsRdpClient2.AdvancedSettings3.RDPPort = Favorite.Port; axMsRdpClient2.AdvancedSettings3.ContainerHandledFullScreen = -1; axMsRdpClient2.AdvancedSettings3.DisplayConnectionBar = Favorite.DisplayConnectionBar; // Use ConnectToServerConsole or ConnectToAdministerServer based on implementation if (axMsRdpClient2.AdvancedSettings3 is MSTSCLib6.IMsRdpClientAdvancedSettings6) ((MSTSCLib6.IMsRdpClientAdvancedSettings6)axMsRdpClient2.AdvancedSettings3).ConnectToAdministerServer = Favorite.ConnectToConsole; else axMsRdpClient2.AdvancedSettings3.ConnectToServerConsole = Favorite.ConnectToConsole; axMsRdpClient2.OnRequestGoFullScreen += new EventHandler(axMsTscAx_OnRequestGoFullScreen); axMsRdpClient2.OnRequestLeaveFullScreen += new EventHandler(axMsTscAx_OnRequestLeaveFullScreen); axMsRdpClient2.OnDisconnected += new IMsTscAxEvents_OnDisconnectedEventHandler(axMsTscAx_OnDisconnected); axMsRdpClient2.OnWarning += new IMsTscAxEvents_OnWarningEventHandler(axMsRdpClient2_OnWarning); axMsRdpClient2.OnFatalError += new IMsTscAxEvents_OnFatalErrorEventHandler(axMsRdpClient2_OnFatalError); Text = "Connecting to RDP Server..."; axMsRdpClient2.FullScreen = true; } catch(Exception exc) { Terminals.Logging.Log.Warn("There was an exception setting an RDP Value.", exc); } axMsRdpClient2.Connect(); return true; } catch(Exception exc) { Terminals.Logging.Log.Fatal("Connecting to RDP", exc); return false; } }