Get the logged on user name in C#

前端 未结 4 1556
深忆病人
深忆病人 2020-12-19 03:32

How do i get the current logged on user name in windows 7 (i.e the user who is physically logged on to the console in which the program that i am launching is running).

4条回答
  •  Happy的楠姐
    2020-12-19 04:07

    You want the user name of your session. You can find out your session ID by calling ProcessIdToSessionId. Then use WTSQuerySessionInformation to find out the user name.

提交回复
热议问题