Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Security.Principal;
  7. using Cassia;
  8.  
  9. namespace ConsoleApplication5
  10. {
  11. class Program
  12. {
  13. static List<string> GetUsers(string computer)
  14. {
  15. // initialize the output variable
  16. List<string> shesaid = new List<String>();
  17. // create the handle object
  18. ITerminalServicesManager manager = new TerminalServicesManager();
  19. // im a little unclear on what this line is actually saying
  20. using (ITerminalServer server = manager.GetRemoteServer(computer))
  21. {
  22. // call the open method that bundles with the ITerminalServer object
  23. server.Open();
  24. // grab the sessions on `computer`
  25. foreach (ITerminalServicesSession session in server.GetSessions())
  26. {
  27. NTAccount account = session.UserAccount;
  28. if (account != null)
  29. {
  30. shesaid.Add(account.ToString());
  31. }
  32. else
  33. {
  34. // there are some sessions that have null userAccount values so this is a no-no
  35. // shesaid.Add("OPEN");
  36. // do nothing instead and call it open if shesaid contains no entries when its time to return
  37. }
  38. }
  39. }
  40.  
  41. // conditional block goes here to see if there are indexes to shesaid
  42. return shesaid;
  43. }
  44.  
  45. static void Main(string[] args)
  46. {
  47. List<string> userlist= GetUsers("k9");
  48. // need to replace this with a foreach loop on userlist
  49. foreach (string element in userlist)
  50. {
  51. Console.WriteLine(element);
  52. }
  53. var userwait = Console.ReadLine();
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement