public void Connect(string server, bool headless, Kohl.Framework.Security.Credential credentials) { // This prevents SharpDevelop and Visual Studio from both an exception in design mode for controls using this HistoryTreeView and from crashing when opening the // designer for this class. if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) { return; } this.credentials = credentials; try { this.splitContainer1.Panel1Collapsed = headless; if (server != "") { this.ServerNameComboBox.Text = server; Connect(credentials); } } catch (Exception exc) { Log.Error("Connection failure.", exc); } }
public void Connect(Kohl.Framework.Security.Credential credentials) { progress.Visible = true; splitContainer1.Visible = false; this.SelectedSession = null; this.dataGridView1.DataSource = null; this.dataGridView2.DataSource = null; this.propertyGrid1.SelectedObject = null; this.server = TerminalServer.LoadServer(this.ServerNameComboBox.Text, credentials); progress.Visible = false; splitContainer1.Visible = true; if (this.server.IsTerminalServer) { this.dataGridView1.DataSource = this.server.Sessions; if (this.dataGridView1.Columns.Count > 0) { this.dataGridView1.Columns[1].Visible = false; } if (this.server.Sessions == null) { MessageBox.Show("Terminals was unable to enumerate your server's sessions." + (this.server.Errors != null & this.server.Errors.Count > 0 ? "\n" + this.server.Errors[0] : "")); } } else { MessageBox.Show("This machine does not appear to be a terminal server."); } }
public static TerminalServer LoadServer(string serverName, Kohl.Framework.Security.Credential credentials) { TerminalServer server = null; System.Threading.Thread t = new System.Threading.Thread(() => server = TerminalServicesApi.GetSessions(serverName, credentials)); t.Start(); while (t.ThreadState == System.Threading.ThreadState.Running) { System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(100); } return(server); }
public void Connect(string server, bool headless, Kohl.Framework.Security.Credential credentials) { // This prevents SharpDevelop and Visual Studio from both an exception in design mode for controls using this HistoryTreeView and from crashing when opening the // designer for this class. if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) return; this.credentials = credentials; try { this.splitContainer1.Panel1Collapsed = headless; if (server != "") { this.ServerNameComboBox.Text = server; Connect(credentials); } } catch (Exception exc) { Log.Error("Connection failure.", exc); } }
public static TerminalServer GetSessions(string serverName, Kohl.Framework.Security.Credential credential) { TerminalServer terminalServer = new TerminalServer { ServerName = serverName }; Kohl.Framework.Security.Impersonator impersonator = null; // Start impersonation if we requested to do so ... try { if (credential != null) { impersonator = new Kohl.Framework.Security.Impersonator(credential); } } catch (Exception ex) { Log.Warn("Error impersonating RDP session enumerator. Trying to query RDP session details without impersonation ...", ex); } // Open a WTS connection to the server to be able to get details about the sessions and processes running on it IntPtr ptrOpenedServer = IntPtr.Zero; try { ptrOpenedServer = WTSOpenServer(terminalServer.ServerName); } catch (Exception ex) { Log.Error("Error opening WTS server connection. Aborting to query RDP sessions.", ex); return(terminalServer); } if (ptrOpenedServer == IntPtr.Zero) { terminalServer.IsTerminalServer = false; return(terminalServer); } terminalServer.ServerPointer = ptrOpenedServer; terminalServer.IsTerminalServer = true; // Try to get information about the sessions and the clients connected to it. GetClientInfos(terminalServer); // Try to get information about the server's processes. GetProcessInfos(terminalServer); if (ptrOpenedServer != IntPtr.Zero) { WTSCloseServer(ptrOpenedServer); } if (impersonator != null) { impersonator.Dispose(); } return(terminalServer); }