使用wmi获取活动会话(Win32_LogonSession也返回非活动/旧会话)

时间:2011-06-22 10:40:36

标签: c# .net wmi interactive-session

有没有办法只显示与wmi的活动会话? 问题是Win32_LogonSession还显示了非活动/断开连接的会话。

ManagementScope scope = new ManagementScope(ManagementPath.DefaultPath);
SelectQuery query = new SelectQuery("Win32_LogonSession");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection results = searcher.Get();
foreach (ManagementObject mo in results)
{
    PrintWmiObject(mo);
}

这个的输出是这样的

  

AuthenticationPackage - Kerberos

     标题 -

     

描述 -

     

InstallDate -

     

LogonId - 10179411

     

LogonType - 10

     

姓名 -

     

StartTime - 20110617083244.547220 + 120

     

状态 -

1 个答案:

答案 0 :(得分:0)

怎么样:

SelectQuery query = new SelectQuery("Select * from Win32_LogonSession Where LogonType = 10")