private void ReconnectForResize()
        {
            if ((RDPVersion < Versions.RDC80))
            {
                return;
            }
            if (!((InterfaceControl.Info.Resolution == RDPResolutions.FitToWindow) ||
                  (InterfaceControl.Info.Resolution == RDPResolutions.Fullscreen)))
            {
                return;
            }
            var size         = Fullscreen ? Control.Size : Screen.FromControl(Control).Bounds.Size;
            var msRdpClient8 = (IMsRdpClient8)RDP_Client.GetOcx(); //ToDO

            msRdpClient8.Reconnect((uint)size.Width, (uint)size.Height);
        }
Exemplo n.º 2
0
        public override void Connect(DbItemRemoteLink linkSettings, DbItemSetting lastSetting)
        {
            DbItemSettingRdp lastSettingRdp = lastSetting as DbItemSettingRdp;

            if (lastSettingRdp == null)
            {
                return;
            }

            //分离服务器地址和端口
            string[] addr = linkSettings.Server.Split(':');
            int      port = 3389;

            if (addr.Length > 1)
            {
                int.TryParse(addr[1], out port);
            }
            if (port <= 0)
            {
                port = 3389;
            }

            //初始化远程连接属性
            if (MsRdpClient7 != null) //win7及以下版本
            {
                MsRdpClient7.Server   = addr[0];
                MsRdpClient7.UserName = linkSettings.UserName;
                MsRdpClient7.AdvancedSettings2.ClearTextPassword = linkSettings.Password;
                MsRdpClient7.AdvancedSettings2.RDPPort           = port;
                MsRdpClientOcx = (IMsRdpClientNonScriptable5)MsRdpClient7.GetOcx();
                MsRdpClientOcx.PromptForCredentials         = false; //凭据提示对话框
                MsRdpClientOcx.AllowPromptingForCredentials = true;  //显示密码输入框
                MsRdpClientOcx.DisableConnectionBar         = true;  //禁用连接栏

                //将窗口句柄设置或检索为控件显示的任何对话框的父窗口
                var parentHwnd = CommonServices.HWNDtoRemotableHandle(new WindowInteropHelper(Window.GetWindow(this)).Handle);
                MsRdpClientOcx.set_UIParentWindowHandle(ref parentHwnd);

                MsRdpClient7.AdvancedSettings.BitmapPeristence           = 1;     //启用位图缓存
                MsRdpClient7.AdvancedSettings.Compress                   = 1;     //启用压缩
                MsRdpClient7.AdvancedSettings.ContainerHandledFullScreen = 1;     //启用容器处理的全屏模式。
                MsRdpClient7.AdvancedSettings2.BitmapPersistence         = 1;     //持久位图缓存
                MsRdpClient7.AdvancedSettings2.CachePersistenceActive    = 1;     //持久位图缓存
                MsRdpClient7.AdvancedSettings2.GrabFocusOnConnect        = false; //连接的时候获取焦点
                MsRdpClient7.AdvancedSettings7.EnableCredSspSupport      = true;  //指定是否为此连接启用凭据安全服务提供程序

                //分辨率
                if (lastSettingRdp.SizeIndex == DbItemSetting.DESKSIZE_AUTO)//自适应分辨率
                {
                    Window windows = Window.GetWindow(this);
                    MsRdpClient7.DesktopWidth  = (int)windows.Width - 4;
                    MsRdpClient7.DesktopHeight = (int)windows.Height - 34;
                }
                else
                {
                    var size = lastSettingRdp.GetDeskTopSize();
                    MsRdpClient7.DesktopWidth  = (int)size.Width;
                    MsRdpClient7.DesktopHeight = (int)size.Height;
                }

                //性能选项
                if (lastSettingRdp.Performance != DbItemSettingRdp.CONNECTION_TYPE_AUTO)
                {
                    MsRdpClient7.AdvancedSettings8.NetworkConnectionType = (uint)lastSettingRdp.Performance;
                }
                //颜色深度
                switch (lastSettingRdp.ColorDepthMode)
                {
                case DbItemSettingRdp.COLOR_15BPP: MsRdpClient7.ColorDepth = 15; break;

                case DbItemSettingRdp.COLOR_16BPP: MsRdpClient7.ColorDepth = 16; break;

                case DbItemSettingRdp.COLOR_24BPP: MsRdpClient7.ColorDepth = 24; break;

                case DbItemSettingRdp.COLOR_32BPP: MsRdpClient7.ColorDepth = 32; break;

                default: MsRdpClient7.ColorDepth = 32; break;
                }
                //音频
                MsRdpClient7.AdvancedSettings6.AudioRedirectionMode = (uint)lastSettingRdp.AudioRedirectionMode - 1;
                //组合键
                MsRdpClient7.SecuredSettings2.KeyboardHookMode = lastSettingRdp.KeyboardHookMode - 1;
                //本地资源
                MsRdpClient7.AdvancedSettings2.RedirectPrinters   = lastSettingRdp.RedirectionPrintf.Value ? true : false;    //打印机
                MsRdpClient7.AdvancedSettings6.RedirectClipboard  = lastSettingRdp.RedirectionClipboard.Value ? true : false; //剪贴板重定向
                MsRdpClient7.AdvancedSettings3.RedirectSmartCards = lastSettingRdp.RedirectionsMartcard.Value ? true : false; //智能卡重定向
                MsRdpClient7.AdvancedSettings3.RedirectPorts      = lastSettingRdp.RedirectionsPort.Value ? true : false;     //端口重定向
                MsRdpClient7.AdvancedSettings3.RedirectDrives     = lastSettingRdp.RedirectionsDriver.Value ? true : false;   //驱动器重定向


                MsRdpClient7.AdvancedSettings4.ConnectionBarShowMinimizeButton = false;//显示全部工具栏上的最小化按钮
                MsRdpClient7.AdvancedSettings7.ConnectToAdministerServer       = false;

                MsRdpClient7.Connect();
                User32.EnumChildWindows(MsRdpClient7.Handle, EnumWindowsProc, IntPtr.Zero);
            }
            else //win8 及以上版本
            {
                MsRdpClient9.Server   = addr[0];
                MsRdpClient9.UserName = linkSettings.UserName;
                MsRdpClient9.AdvancedSettings2.ClearTextPassword = linkSettings.Password;
                MsRdpClient9.AdvancedSettings2.RDPPort           = port;
                MsRdpClientOcx = (IMsRdpClientNonScriptable5)MsRdpClient9.GetOcx();
                MsRdpClientOcx.PromptForCredentials         = false; //凭据提示对话框
                MsRdpClientOcx.AllowPromptingForCredentials = true;  //显示密码输入框
                MsRdpClientOcx.DisableConnectionBar         = true;  //禁用连接栏

                //将窗口句柄设置或检索为控件显示的任何对话框的父窗口
                var parentHwnd = CommonServices.HWNDtoRemotableHandle(new WindowInteropHelper(Window.GetWindow(this)).Handle);
                MsRdpClientOcx.set_UIParentWindowHandle(ref parentHwnd);

                MsRdpClient9.AdvancedSettings.BitmapPeristence           = 1;     //启用位图缓存
                MsRdpClient9.AdvancedSettings.Compress                   = 1;     //启用压缩
                MsRdpClient9.AdvancedSettings.ContainerHandledFullScreen = 1;     //启用容器处理的全屏模式。
                MsRdpClient9.AdvancedSettings2.BitmapPersistence         = 1;     //持久位图缓存
                MsRdpClient9.AdvancedSettings2.CachePersistenceActive    = 1;     //持久位图缓存
                MsRdpClient9.AdvancedSettings2.GrabFocusOnConnect        = false; //连接的时候获取焦点
                MsRdpClient9.AdvancedSettings7.EnableCredSspSupport      = true;  //指定是否为此连接启用凭据安全服务提供程序

                //分辨率
                if (lastSettingRdp.SizeIndex == DbItemSetting.DESKSIZE_AUTO)//自适应分辨率
                {
                    Window windows = Window.GetWindow(this);
                    MsRdpClient9.DesktopWidth  = (int)windows.Width - 4;
                    MsRdpClient9.DesktopHeight = (int)windows.Height - 34;
                }
                else
                {
                    var size = lastSettingRdp.GetDeskTopSize();
                    MsRdpClient9.DesktopWidth  = (int)size.Width;
                    MsRdpClient9.DesktopHeight = (int)size.Height;
                }
                //性能选项
                if (lastSettingRdp.Performance == DbItemSettingRdp.CONNECTION_TYPE_AUTO)
                {
                    MsRdpClient9.AdvancedSettings9.BandwidthDetection = true;                                                                     //自动检查带宽
                }
                else
                {
                    MsRdpClient9.AdvancedSettings8.NetworkConnectionType = (uint)lastSettingRdp.Performance;
                }
                //颜色深度
                switch (lastSettingRdp.ColorDepthMode)
                {
                case DbItemSettingRdp.COLOR_15BPP: MsRdpClient9.ColorDepth = 15; break;

                case DbItemSettingRdp.COLOR_16BPP: MsRdpClient9.ColorDepth = 16; break;

                case DbItemSettingRdp.COLOR_24BPP: MsRdpClient9.ColorDepth = 24; break;

                case DbItemSettingRdp.COLOR_32BPP: MsRdpClient9.ColorDepth = 32; break;

                default: MsRdpClient9.ColorDepth = 32; break;
                }
                //音频
                MsRdpClient9.AdvancedSettings6.AudioRedirectionMode = (uint)lastSettingRdp.AudioRedirectionMode - 1;
                //录音设备
                MsRdpClient9.AdvancedSettings8.AudioCaptureRedirectionMode = lastSettingRdp.AudioCaptureRedirectionMode == DbItemSettingRdp.AAUDIOCAPTURE_TRUE;
                //组合键
                MsRdpClient9.SecuredSettings2.KeyboardHookMode = lastSettingRdp.KeyboardHookMode - 1;
                //重定向
                MsRdpClient9.AdvancedSettings2.RedirectPrinters   = lastSettingRdp.RedirectionPrintf.Value ? true : false;    //打印机
                MsRdpClient9.AdvancedSettings6.RedirectClipboard  = lastSettingRdp.RedirectionClipboard.Value ? true : false; //剪贴板重定向
                MsRdpClient9.AdvancedSettings3.RedirectSmartCards = lastSettingRdp.RedirectionsMartcard.Value ? true : false; //智能卡重定向
                MsRdpClient9.AdvancedSettings3.RedirectPorts      = lastSettingRdp.RedirectionsPort.Value ? true : false;     //端口重定向
                MsRdpClient9.AdvancedSettings3.RedirectDrives     = lastSettingRdp.RedirectionsDriver.Value ? true : false;   //驱动器重定向
                MsRdpClient9.AdvancedSettings4.ConnectionBarShowMinimizeButton = false;                                       //显示全部工具栏上的最小化按钮

                MsRdpClient9.Connect();
                User32.EnumChildWindows(MsRdpClient9.Handle, EnumWindowsProc, IntPtr.Zero);
            }
        }
Exemplo n.º 3
0
        private void connectRemoteDesktop(string loginname, string password, string serverIP, int serverPort = 3389, string title = "", bool useMultimon = false)
        {
            Form form = new Form();

            form.ShowIcon = false;
            form.Name     = string.Format("form_rdp_{0}_{1}", serverIP.Replace(".", "_"), DateTime.Now.Second.ToString());
            form.Text     = title;
            form.Size     = new Size(1024, 768);
            form.Resize  += new System.EventHandler(this.RDPForm_Resize);
            form.Closing += new CancelEventHandler(this.RDPForm_Closing);

            Rectangle ScreenArea;

            if (Screen.AllScreens.Length > 1)
            {
                Trace.TraceInformation("Screen Count = {0}", Screen.AllScreens.Length);
                Screen scr = null;
                for (int i = 0; i < Screen.AllScreens.Length; i++)
                {
                    scr = Screen.AllScreens[i];
                    Trace.TraceInformation("Screen[{0}]:Primary = {1}", i, scr.Primary);
                    if (scr.Primary)
                    {
                        break;
                    }
                }
                if (scr != null)
                {
                    ScreenArea = scr.Bounds;
                    Trace.TraceInformation("set ScreenArea:width={0} , height={1}", ScreenArea.Width, ScreenArea.Height);
                }
                else
                {
                    ScreenArea = Screen.PrimaryScreen.Bounds;
                }
            }
            else
            {
                ScreenArea = Screen.PrimaryScreen.Bounds;
            }
            AxMsRdpClient7NotSafeForScripting axMsRdpc = new AxMsRdpClient7NotSafeForScripting();

            ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).BeginInit();
            axMsRdpc.Dock    = DockStyle.Fill;
            axMsRdpc.Enabled = true;
            axMsRdpc.Name    = string.Format("axMsRdpc_{0}_{1}", serverIP.Replace(".", "_"), DateTime.Now.Second.ToString());

            // bind rdp connect's events
            axMsRdpc.OnDisconnected        += RDC_Event_OnDisconnected;
            axMsRdpc.OnLeaveFullScreenMode += RDC_Event_OnLeaveFullScreenMode;
            axMsRdpc.OnEnterFullScreenMode += RDC_Event_OnEnterFullScreenMode;

            form.Controls.Add(axMsRdpc);
            form.Show();
            ((System.ComponentModel.ISupportInitialize)(axMsRdpc)).EndInit();

            IMsRdpClientNonScriptable5 sc = (IMsRdpClientNonScriptable5)axMsRdpc.GetOcx();

            sc.UseMultimon = useMultimon;

            axMsRdpc.Server   = serverIP;
            axMsRdpc.UserName = loginname;
            axMsRdpc.AdvancedSettings7.RDPPort = Convert.ToInt32(serverPort);
            axMsRdpc.AdvancedSettings7.EnableCredSspSupport = true;
            axMsRdpc.AdvancedSettings7.ClearTextPassword    = password;
            axMsRdpc.AdvancedSettings7.Compress             = 1;
            //axMsRdpc.AdvancedSettings7.SmartSizing = true; //自动缩放图像
            axMsRdpc.AdvancedSettings7.ContainerHandledFullScreen = 0;

            axMsRdpc.ColorDepth = 32;
            axMsRdpc.FullScreen = true;
            Trace.TraceInformation("ScreenArea:width={0} , height={1}", ScreenArea.Width, ScreenArea.Height);
            axMsRdpc.DesktopWidth  = ScreenArea.Width;
            axMsRdpc.DesktopHeight = ScreenArea.Height;

            axMsRdpc.Connect();

            rdp2formMap.Add(axMsRdpc.Name, form);
            form2rdpMap.Add(form.Name, axMsRdpc);
        }