In windows I can log in and switch of user without logging out. Like that I can have multiple users logged in but only one working. How can I know which of the users is currently working.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To my knowledge, the .NET framework does not expose to managed code the API required to achieve this. You will have to p/invoke quite a few WINAPI functions and define at least one structure and some enums on the .NET side.
If you’re willing to follow that path, you can:
Call WTSEnumerateSessions(), passing
WTS_CURRENT_SERVER_HANDLEin thehServerargument,Iterate over the returned WTS_SESSION_INFO structures and locate the one whose
Statemember has theWTSActiveandWTSConnectedbits set (there should only be one in your case),Pass the
SessionIdmember of that structure to WTSQuerySessionInformation(), specifyingWTSUserNamein theWTSInfoClassargument,Read the user name from the returned buffer,
Use WTSFreeMemory() to free the buffer and the array of
WTS_SESSION_INFOstructures.As you can see, this isn’t really trivial. Good luck.