且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-27 23:04:34

什么:

  SelectQuery查询=新SelectQuery(SELECT * FROM Win32_LogonSession其中LogonType = 10)
 

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 -

What about:

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