我想获取特定登录用户的Windows会话ID。如何在C#中完成?
答案 0 :(得分:3)
所以在做了一些挖掘之后,我找到了Cassia库。获取特定用户的会话ID很简单:
ITerminalServicesManager manager = new TerminalServicesManager();
using (ITerminalServer server = manager.GetLocalServer())
{
server.Open();
var result = server.GetSessions().Where(x => x.UserName == "name").SingleOrDefault();
Console.WriteLine(result.SessionId);
}