我必须确定用户 session 处于什么状态。即用户是否已登录并处于事件状态,或者用户是否未登录。为此,我使用函数 WTSEnumerateSessions
,然后检查从该函数返回的 WTS_SESSION_INFO
,它有一个状态成员。
根据在线文档。
WTSActive A user is logged on to the WinStation
WTSDisconnected The WinStation is active but the client is disconnected.
问题是我目前登录到我的系统,但我当前 session 返回的状态是 WTSDisconnected
我期望状态是 WTSActive
是否有任何理由为什么会这样?
下面的代码
PWTS_SESSION_INFO pSessionInfo(nullptr);
DWORD countOfSessions(0);
DWORD sessionIndex(0);
if (WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, // local machine
0, // reserved, must be zero
1, // Version, must be one
&pSessionInfo,
&countOfSessions) == FALSE)
{
return false;
}
if (countOfSessions == 0 || !pSessionInfo)
{
return false;
}
const DWORD currentSession = GetRealSessionID(CurrentSession); //This case we are in session 0
for (; sessionIndex < countOfSessions; ++sessionIndex)
{
WTS_SESSION_INFO& sessionInfo = pSessionInfo[sessionIndex];
if (currentSession == sessionInfo.SessionId)
{
if (sessionInfo.State == WTSActive)
{
return true;
}
}
}
return false;
谢谢
最佳答案
这没有多大意义。最可能的解释是 currentSession
被分配了 0
值,这是运行服务的非交互式隔离 session 的 session ID。
关于c++ - WTS_CONNECTSTATE_CLASS 枚举类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33916774/