3

Since there is absolutely zero documentation by Citrix on their SDK, I am documenting this here.

Using C#, how do I programmatically log a user session off?

Nathan McKaskle
  • 2,926
  • 12
  • 55
  • 93
  • 1
    Who the hell marked this down and why? No research effort is possible where there is no documentation. *Anywhere*. This is literally the wild frontier. Seriously, type StopXASessionByObject into Google and you will find one post with my answer. – Nathan McKaskle Jan 23 '15 at 21:14
  • Perhaps someone down voted it because they expected to see an question.. but it's impressive that you were able to provide some much needed documentation / information for someone in the future if they run into the same issue.. `+1` – MethodMan Jan 23 '15 at 21:19
  • The question is in there, not sure why they didn't see it. It has a question mark after it. Frustrating. – Nathan McKaskle Jan 23 '15 at 21:21
  • sometimes $H!T happens .. I will mark your answer as a viable since you are bright enough to compile an undocumented solution.. good job – MethodMan Jan 23 '15 at 21:24

1 Answers1

3

Use the simple method below to log off a user session by parsing through sessions and logging off an individual session.

using Citrix.Common.Sdk;
using Citrix.XenApp.Sdk;
using Citrix.XenApp.Commands;
using Citrix.Management.Automation;

    private void logoffUser(string strUser)
    {
        GetXASessionByFarm sessions = new GetXASessionByFarm(true);

        foreach (XASession session in CitrixRunspaceFactory.DefaultRunspace.ExecuteCommand(sessions))
        {
            if (session.AccountName.ToLower() == objWINSDomainName + "\\" + strUser)
            {
                var cmd = new StopXASessionByObject(new[] { session });
                CitrixRunspaceFactory.DefaultRunspace.ExecuteCommand(cmd);
            }
        }
    }
Nathan McKaskle
  • 2,926
  • 12
  • 55
  • 93