Getting logged-on username from a service

前端 未结 4 1958
孤街浪徒
孤街浪徒 2021-01-03 10:05

I have a service that I had to log on to the local admin to install. The pupose of this service to log when a user is logging in or out to record their username. I finally f

4条回答
  •  隐瞒了意图╮
    2021-01-03 10:33

    Try to change the Account() method inserting the sessionId parameter and passing the changeDescription.SessionId to the method WTSQueryUserToken

    public static string Account(uint sessionId)
    {
         IntPtr token = IntPtr.Zero;
         String account = String.Empty;
         if (WTSQueryUserToken(sessionId, out token))
         { 
         ...
         ...
    

    p.s.: Run your service with LocalSystem account

提交回复
热议问题