Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How do I log off a Citrix XenApp User Session?

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?

like image 824
Nathan McKaskle Avatar asked Jan 17 '26 22:01

Nathan McKaskle


1 Answers

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);
            }
        }
    }
like image 89
Nathan McKaskle Avatar answered Jan 20 '26 10:01

Nathan McKaskle