how to get logged in user name from window service

后端 未结 2 733
醉话见心
醉话见心 2021-01-24 06:32

how to get logged in user name from window service. when i do the same thing using Environment.UserName i get username as \"System\".

thanks Arvind

2条回答
  •  长发绾君心
    2021-01-24 07:21

    Check this link which talks about getting current loggedin user from window service -

    http://www.pcreview.co.uk/forums/thread-3460184.php

    Taken from above link itself -

    There can be 0 or more current logged in users. If you want all of the 0 or 1 users who are currently logged in at the console then P/Invoke to WTSGetActiveConsoleSessionId and WTSQuerySessionInformation. If you want all of the users then you'll need to call WTSQuerySessionInformation in a loop.

提交回复
热议问题