private void GetSessionsBG() { try { RDP.TerminalSessions tS = new RDP.TerminalSessions(); Security.Impersonator sU = new Security.Impersonator(); RDP.Sessions tsSessions = new RDP.Sessions(); sU.StartImpersonation(tDomain, tUserName, tPassword); try { //Trace.WriteLine("Opening connection to server: " & tServerName) if (tS.OpenConnection(tServerName) == true) { tServerHandle = tS.ServerHandle; //Trace.WriteLine("Trying to get sessions") tsSessions = tS.GetSessions(); } } catch (Exception) { } int i = 0; //Trace.WriteLine("Sessions Count: " & tsSessions.Count) if (tServerName == this._CurrentHost) { for (i = 0; i <= tsSessions.ItemsCount - 1; i++) { ListViewItem lItem = new ListViewItem(); lItem.Tag = tsSessions[i].SessionID; lItem.Text = (string)(tsSessions[i].SessionUser); lItem.SubItems.Add(tsSessions[i].SessionState); lItem.SubItems.Add(Strings.Replace((string)(tsSessions[i].SessionName), Constants.vbNewLine, "", 1, -1, 0)); //Trace.WriteLine("Session " & i & ": " & tsSessions(i).SessionUser) AddToList(lItem); } } sU.StopImpersonation(); sU = null; tS.CloseConnection(tServerHandle); } catch (Exception ex) { Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, Language.strSessionGetFailed + Constants.vbNewLine + ex.Message, true); } }
private void GetSessionsBG() { try { RDP.TerminalSessions tS = new RDP.TerminalSessions(); Security.Impersonator sU = new Security.Impersonator(); RDP.Sessions tsSessions = new RDP.Sessions(); sU.StartImpersonation(tDomain, tUserName, tPassword); try { //Trace.WriteLine("Opening connection to server: " & tServerName) if (tS.OpenConnection(tServerName) == true) { tServerHandle = tS.ServerHandle; //Trace.WriteLine("Trying to get sessions") tsSessions = tS.GetSessions(); } } catch (Exception) { } int i = 0; //Trace.WriteLine("Sessions Count: " & tsSessions.Count) if (tServerName == this._CurrentHost) { for (i = 0; i <= tsSessions.ItemsCount - 1; i++) { ListViewItem lItem = new ListViewItem(); lItem.Tag = tsSessions[i].SessionID; lItem.Text = (string)(tsSessions[i].SessionUser); lItem.SubItems.Add(tsSessions[i].SessionState); lItem.SubItems.Add(Strings.Replace((string)(tsSessions[i].SessionName), Constants.vbNewLine, "", 1, -1, 0)); //Trace.WriteLine("Session " & i & ": " & tsSessions(i).SessionUser) AddToList(lItem); } } sU.StopImpersonation(); sU = null; tS.CloseConnection(tServerHandle); } catch (Exception ex) { Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, Language.strSessionGetFailed + Constants.vbNewLine + ex.Message, true); } }