Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Security.Principal;
- using Cassia;
- namespace ConsoleApplication5
- {
- class Program
- {
- static List<string> GetUsers(string computer)
- {
- // initialize the output variable
- List<string> shesaid = new List<String>();
- // create the handle object
- ITerminalServicesManager manager = new TerminalServicesManager();
- // im a little unclear on what this line is actually saying
- using (ITerminalServer server = manager.GetRemoteServer(computer))
- {
- // call the open method that bundles with the ITerminalServer object
- server.Open();
- // grab the sessions on `computer`
- foreach (ITerminalServicesSession session in server.GetSessions())
- {
- NTAccount account = session.UserAccount;
- if (account != null)
- {
- shesaid.Add(account.ToString());
- }
- else
- {
- // there are some sessions that have null userAccount values so this is a no-no
- // shesaid.Add("OPEN");
- // do nothing instead and call it open if shesaid contains no entries when its time to return
- }
- }
- }
- // conditional block goes here to see if there are indexes to shesaid
- return shesaid;
- }
- static void Main(string[] args)
- {
- List<string> userlist= GetUsers("k9");
- // need to replace this with a foreach loop on userlist
- foreach (string element in userlist)
- {
- Console.WriteLine(element);
- }
- var userwait = Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement