Why I'm receiving Active Session ID from Windows Service before the user login to the system after Restart?

Sireesha Pallela 21 Reputation points
2022-10-27T14:28:46.02+00:00

While I am restarting the system, getting the active session ID from WTSEnumerateSessions() before the user logged into the system. Actually I want to perform some other action after the user logged into the system, But I'm receiving the active session Id before the user logged in.

I wrote the code, like this:

WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo,

        &dwCount);  
    for (DWORD i = 0; i < dwCount; i++)  
           {  
        if (WTSActive == pSessionInfo[i].State)  
                    {  
            dwSessionId = pSessionInfo[i].SessionId;  

        }  
    }  

I don't know why it is behaving like this, if anyone knows the reason. Can you please help me.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,906 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RLWA32 32,151 Reputation points
    2022-10-27T14:58:44.243+00:00

    A default Windows policy will automatically logon the last logged-on user when the system starts and then lock the workstation. It is likely that is what is happening and what you perceive as a user logon is actually the user unlocking the workstation. The logon took place automatically before any user interaction.

    The related policy -

    254842-logon-policy.png