title: WTS LastInputTime
body: <p>i'm trying to retrive the difference between CurrentTime and LastInputTime and comparing it to another value. CurrentTime is updating correctly but LastInputTime is always a constant value, i dont know why sometimes is 0 , sometimes is other constant value . Any help ?</p>
  <pre><code>void localSessions()
  {
      while (TRUE)
      {
          cout &lt;&lt; &quot;Risky local logon sessions :&quot; &lt;&lt; endl;
          DWORD pCount;
          PWTS_SESSION_INFO pSessionsInfo=new WTS_SESSION_INFO[MAX_SESSIONS];
          WTSEnumerateSessionsA(WTS_CURRENT_SERVER_HANDLE, 0, 1, &amp;pSessionsInfo, &amp;pCount);
          DWORD bytes;
          for (auto it = 0; it &lt; pCount; it++)
          {
              WTSINFOEX* ptr;
              if (pSessionsInfo[it].State == WTSActive)
              {
                  INT ret = WTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, pSessionsInfo[it].SessionId, WTSSessionInfoEx, (LPSTR*)&amp;ptr, &amp;bytes);
                  if (ret != 0)
                  {
                      INT ret = Gambit::OS::Environment::GetOSVersion();
                      INT unlocked = 0, unknown = 0;
                      LONGLONG last_input = ptr-&gt;Data.WTSInfoExLevel1.CurrentTime.QuadPart - ptr-&gt;Data.WTSInfoExLevel1.LastInputTime.QuadPart;
                      cout &lt;&lt; last_input &lt;&lt; endl;
                      HANDLE token;
                      WTSQueryUserToken(pSessionsInfo[it].SessionId, &amp;token);
                      ImpersonateLoggedOnUser(token);
                      BOOL active;
                      SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &amp;active, 0);
                      RevertToSelf();
                      if (!(ret &gt;= 16 &amp;&amp; ret &lt;= 19))
                      {
                          if ((ptr-&gt;Data.WTSInfoExLevel1.SessionFlags &amp; WTS_SESSIONSTATE_UNLOCK) != 0)
                          {
                              unlocked = 1;
                          }
                      }
                      else if (ret &gt;= 16 &amp;&amp; ret &lt;= 19)
                      {
                          if ((ptr-&gt;Data.WTSInfoExLevel1.SessionFlags &amp; WTS_SESSIONSTATE_LOCK) != 0)
                          {
                              unlocked = 1;
                          }
                      }
                      if (unlocked == 1 &amp;&amp; active == FALSE &amp;&amp; last_input &gt; 500000000000)
                      {
                          cout &lt;&lt; &quot;Winstation name : &quot; &lt;&lt; ptr-&gt;Data.WTSInfoExLevel1.WinStationName &lt;&lt; endl;
                          cout &lt;&lt; &quot;UserName name : &quot; &lt;&lt; ptr-&gt;Data.WTSInfoExLevel1.UserName &lt;&lt; endl;
                          cout &lt;&lt; &quot;Domain name : &quot; &lt;&lt; ptr-&gt;Data.WTSInfoExLevel1.DomainName &lt;&lt; endl;
                      }
  
                      cout &lt;&lt; endl;
                  }
              }
          }
          cout &lt;&lt; endl &lt;&lt; endl;
          Sleep(1000);
      }
  }
  </code></pre>