I actually found another solution, that works quite well - using
Cassia
ITerminalServicesManager manager = new TerminalServicesManager();
using (ITerminalServer server = manager.GetLocalServer())
{
server.Open();
foreach (ITerminalServicesSession session in server.GetSessions())
{
NTAccount account = session.UserAccount;
if (session.IdleTime > minutes && account != null && account.ToString().Contains("admin") == false)
{
listBox1.Items.Add(session.UserAccount + " " + DateTime.Now.ToString());
session.Disconnect();
Settings.Default.amount++;
Settings.Default.Save();
label1.Text = "Accounts disconnected: " + Settings.Default.amount.ToString();
}
else { }
}
}