Find out the current user's username - when multiple users are logged on

后端 未结 3 1513
我在风中等你
我在风中等你 2021-01-24 15:50

\"User A\" is logged on My application recognizes Environment.Username as \"User A\"

Now in Windows, I click on Switch user ... \"User B\" logs on

\"User A\'s\"

3条回答
  •  灰色年华
    2021-01-24 16:33

    There is no such thing as the currently active user since there can be more than one (Terminal server)

    You can use GetSystemMetrics(SM_REMOTESESSION) to check if this a "local" session, and WTSGetActiveConsoleSessionId to get the session id of the console session (Currently logged on user as you call it) You can use WTSRegisterSessionNotification to get notified when this changes. ProcessIdToSessionId(GetCurrentProcess(),...) will get you the session id your process is in. Finally, WTSQuerySessionInformation() will get you info about a specific session.

提交回复
热议问题