I want to know from within a Windows Service (Local System Account) the number of logged in user on the system, i've implemented this method on my windows Service :
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
base.OnSessionChange(changeDescription);
switch (changeDescription.Reason)
{
case SessionChangeReason.SessionLogon:
userCount += 1;
break;
case SessionChangeReason.SessionLogoff:
userCount -= 1;
break;
case SessionChangeReason.RemoteConnect:
userCount += 1;
break;
case SessionChangeReason.RemoteDisconnect:
userCount -= 1;
break;
default:
break;
}
}
The problem is that if i start this service manually from a user session and not at system startup, the variable userCount = 0 , while when i launched the service there was a user logged in ? How can i get the number of the logged in user on a system in a given moment ? Is there a way to do it ?