Get active sessions with wmi (Win32_LogonSession returns also inactive/old sessions)

风流意气都作罢 提交于 2019-12-07 08:32:47

问题


Is there a way to show only active sessions with wmi? The problem is that Win32_LogonSession shows also inactive/disconnected sessions.

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);
}

The output of this is something like this

AuthenticationPackage - Kerberos

Caption -

Description -

InstallDate -

LogonId - 10179411

LogonType - 10

Name -

StartTime - 20110617083244.547220+120

Status -


回答1:


What about:

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


来源:https://stackoverflow.com/questions/6438515/get-active-sessions-with-wmi-win32-logonsession-returns-also-inactive-old-sessi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!