Get active sessions with wmi (Win32_LogonSession r

2019-05-16 16:01发布

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条回答
三岁会撩人
2楼-- · 2019-05-16 16:40

What about:

SelectQuery query = new SelectQuery("Select * from Win32_LogonSession Where LogonType = 10")
查看更多
登录 后发表回答