开发者

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

开发者 https://www.devze.com 2023-03-15 02:02 出处:网络
Is there a way to show only active sessions with wmi? The problem is that Win32_LogonSession shows also inactive/disconnected sessions.

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 -

开发者_如何学C

LogonId - 10179411

LogonType - 10

Name -

StartTime - 20110617083244.547220+120

Status -


What about:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号