我最终得到了以下方法:计算至少有一个进程在运行的交互式会话的数量.
1)获取每个交互式会话的登录会话ID.
> LSAEnumeratelogonSessions(secur32.dll)
> LsaGetlogonSessionData(secur32.dll)
> sessionData.logonType = SECURITY_LOGON_TYPE.Interactive或sessionData.logonType = SECURITY_logoN_TYPE.RemoteInteractive
> sessionData.LoginID< - 将此值保存在LUID集中.
> LsaFreeReturnBuffer(secur32.dll)
2)获取每个正在运行的进程的登录会话ID.
[首先我们需要将SeDebugPrivilege启用到当前应用程序.]
> GetCurrentProcess(kernel32.dll)
> OpenProcessToken TOKEN_ADJUST_PRIVILEGES(advapi32.dll)
> LookupPrivilegeValue SE_DEBUG_NAME(advapi32.dll)
> AdjustTokenPrivileges(advapi32.dll)
> CloseHandle(kernel32.dll)
[然后检索我们想要的数据.]
> EnumProcesses(psapi.dll)
> OpenProcess PROCESS_QUERY_INFORMATION(kernel32.dll)
> OpenProcessToken TOKEN_QUERY(advapi32.dll)
> GetTokenInformation TOKEN_INFORMATION_CLASS.TokenStatistics(advapi32.dll)
> accessTokenStatistics.AuthenticationId< - 将此值保存在LUID集中.
> CloseHandle(kernel32.dll)
3)设置交叉点基数
interactiveSessionsCount = | { sessionData.LoginID } ∩ { accessTokenStatistics.AuthenticationId } |
Obs:sessionData.LoginID和accessTokenStatistics.AuthenticationId都是LUID类型.