/// <summary> /// 连接Windows远程桌面 /// </summary> /// <param name="server"></param> private void ConnectWindowsDesktop(RDSServer server) { AxMSTSCLib.AxMsRdpClient9NotSafeForScripting rdp = null; // 如果Panel中包含子控件,则让远程桌面控件启动连接 if (currentRDPanel.HasChildren) { rdp = (AxMSTSCLib.AxMsRdpClient9NotSafeForScripting)currentRDPanel.Controls[0]; // About Connected https://msdn.microsoft.com/en-us/library/aa382835(v=vs.85).aspx if (rdp.Connected == 0) { // 防止服务器相关参数变更 rdp.Tag = server.ServerID.ToString(); rdp.Name = "rdp_" + server.ServerID.ToString(); rdp.Server = server.ServerAddress; rdp.AdvancedSettings9.RDPPort = server.ServerPort; rdp.UserName = server.UserName; rdp.AdvancedSettings9.ClearTextPassword = EncryptUtils.DecryptServerPassword(server); rdp.Connect(); } } // 如果远程桌面控件不存在,则创建 if (rdp == null) { rdp = new AxMSTSCLib.AxMsRdpClient9NotSafeForScripting(); rdp.Width = this.splitContainer1.Panel2.Width; rdp.Height = this.splitContainer1.Panel2.Height; rdp.Dock = System.Windows.Forms.DockStyle.None; currentRDPanel.Controls.Add(rdp); rdp.Tag = server.ServerID.ToString(); rdp.Name = "rdp_" + server.ServerID.ToString(); rdp.Server = server.ServerAddress; rdp.UserName = server.UserName; rdp.CausesValidation = false; rdp.AdvancedSettings9.EnableCredSspSupport = true; rdp.AdvancedSettings9.RDPPort = server.ServerPort; rdp.AdvancedSettings9.ClearTextPassword = EncryptUtils.DecryptServerPassword(server); rdp.AdvancedSettings9.BandwidthDetection = true; rdp.AdvancedSettings.allowBackgroundInput = 1; rdp.ColorDepth = 32; rdp.ConnectingText = "正在连接"; rdp.DisconnectedText = "连接已断开"; rdp.OnConnected += Rdp_OnConnected; rdp.OnDisconnected += Rdp_OnDisconnected; rdp.OnFatalError += Rdp_OnFatalError; rdp.Connect(); } }
void ProcessTaskThread() { try { // imp = new Impersonator(user, domain, password); form = new Form(); Rectangle screen = Screen.PrimaryScreen.WorkingArea; int w = form.Width >= screen.Width ? screen.Width : (screen.Width + form.Width) / 2; int h = form.Height >= screen.Height ? screen.Height : (screen.Height + form.Height) / 2; form.Location = new Point((screen.Width - w) / 2, (screen.Height - h) / 2); form.Size = new Size(w, h); form.Load += (sender, args) => { try { rdpConnection = new AxMSTSCLib.AxMsRdpClient9NotSafeForScripting(); form.Controls.Add(rdpConnection); rdpConnection.Dock = DockStyle.Fill; // rdpConnection.Enabled = false; rdpConnection.Server = server; rdpConnection.Domain = domain; rdpConnection.UserName = user; rdpConnection.AdvancedSettings9.ClearTextPassword = password; rdpConnection.AdvancedSettings9.EnableCredSspSupport = true; if (true) { rdpConnection.OnDisconnected += RdpConnectionOnOnDisconnected; rdpConnection.OnLoginComplete += RdpConnectionOnOnLoginComplete; rdpConnection.OnLogonError += RdpConnectionOnOnLogonError; } rdpConnection.Connect(); Application.Run(form); } catch (Exception ex) { Log.Error(ex.ToString()); Connecting = false; } }; form.Show(); } catch (Exception ex) { Log.Error(ex.ToString()); Connecting = false; } }
void ProcessTaskThread() { try { // if (form != null) return; // imp = new Impersonator(user, domain, password); form = new Form(); Rectangle screen = Screen.PrimaryScreen.WorkingArea; int w = form.Width >= screen.Width ? screen.Width : (screen.Width + form.Width) / 2; int h = form.Height >= screen.Height ? screen.Height : (screen.Height + form.Height) / 2; form.Location = new Point((screen.Width - w) / 2, (screen.Height - h) / 2); form.Size = new Size(w, h); form.Load += (sender, args) => { try { rdpConnection = new AxMSTSCLib.AxMsRdpClient9NotSafeForScripting(); form.Controls.Add(rdpConnection); rdpConnection.Dock = DockStyle.Fill; // rdpConnection.Enabled = false; rdpConnection.Server = server; rdpConnection.Domain = domain; rdpConnection.UserName = user; rdpConnection.AdvancedSettings7.ClearTextPassword = password; rdpConnection.AdvancedSettings7.EnableCredSspSupport = true; //rdpConnection.AdvancedSettings9.ClearTextPassword = password; //// rdpConnection.AdvancedSettings9.EnableCredSspSupport = false; //rdpConnection.AdvancedSettings9.EnableCredSspSupport = true; //rdpConnection.AdvancedSettings9.AuthenticationLevel = 2; //rdpConnection.AdvancedSettings9.EnableCredSspSupport = true; //rdpConnection.AdvancedSettings9.NegotiateSecurityLayer = false; //var ocx = (MSTSCLib.IMsRdpClientNonScriptable7)rdpConnection.GetOcx(); //ocx.EnableCredSspSupport = true; //ocx.AllowCredentialSaving = false; //ocx.PromptForCredentials = false; //ocx.PromptForCredsOnClient = true; //ocx.AllowPromptingForCredentials = false; //ocx.EnableCredSspSupport = true; //ocx.AllowCredentialSaving = false; //ocx.WarnAboutSendingCredentials = false; //ocx.MarkRdpSettingsSecure = true; ////rdp.AdvancedSettings7.DisableRdpdr = 0; ////rdp.CreateVirtualChannels("CH001,CH002"); //var settings = (MSTSCLib.IMsRdpClientAdvancedSettings8)rdpConnection.AdvancedSettings; //settings.allowBackgroundInput = 1; //settings.ClientProtocolSpec = MSTSCLib.ClientSpec.FullMode; //settings.ConnectToServerConsole = true; //settings.EnableCredSspSupport = true; //settings.EncryptionEnabled = 1; //MSTSCLib.IMsRdpClientNonScriptable4 ocx = (MSTSCLib.IMsRdpClientNonScriptable4)rdpConnection.GetOcx(); //ocx.EnableCredSspSupport = true; //ocx.AllowCredentialSaving = false; //ocx.PromptForCredentials = false; //ocx.PromptForCredsOnClient = false; if (true) { rdpConnection.OnDisconnected += RdpConnectionOnOnDisconnected; rdpConnection.OnLoginComplete += RdpConnectionOnOnLoginComplete; rdpConnection.OnLogonError += RdpConnectionOnOnLogonError; rdpConnection.OnWarning += RdpConnection_OnWarning; rdpConnection.OnFatalError += RdpConnection_OnFatalError; rdpConnection.OnAuthenticationWarningDismissed += RdpConnection_OnAuthenticationWarningDismissed; rdpConnection.OnAuthenticationWarningDisplayed += RdpConnection_OnAuthenticationWarningDisplayed; rdpConnection.OnConnected += RdpConnection_OnConnected; rdpConnection.OnConnecting += RdpConnection_OnConnecting; } rdpConnection.Connect(); Application.Run(form); } catch (Exception ex) { Log.Error(ex.ToString()); Connecting = false; } }; form.Show(); } catch (Exception ex) { Log.Error(ex.ToString()); Connecting = false; } }