Get LastInputTime by WinStationQueryInformationW returns with 7 min difference

  • Thread starter Thread starter 355
  • Start date Start date
3

355

Guest
Hi experts,

I have a strangle problem with LastInputTime from WinStationInformationW function. The problem is that it sometimes return LastInputTime with 7 min difference from its actual time. For example: last input time was at 11.10 but it returns 11.03. It usually occurs when the person logs in for the first time at the terminal server. But it can also appear during active session.

I don't think that the problem is in the code, because it apperars ocassionally.

Thank you in advance.

Here is the code:

private enum WINSTATIONINFOCLASS{
WinStationInformation = 8
}
//Works only on Windows 2000/2003
[DllImport("winsta.dll")]
private static extern int WinStationQueryInformationW(
IntPtr hServer,
uint SessionId,
uint WinStationInformation,
[Out] IntPtr Buf,
uint BufLen,
ref uint RetLen);

[DllImport("wtsapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr WTSOpenServer(string ServerName);

[DllImport("wtsapi32.dll")]
private static extern void WTSCloseServer(IntPtr hServer);

public struct WinstaInfo
{
public int SessionId;
public DateTime ConnectTime;
public DateTime DisconnectTime;
public DateTime LastInputTime;
public DateTime LoginTime;
public DateTime CurrentTime;
}

private static DateTime FileTimeToDateTime(System.Runtime.InteropServices.ComTypes.FILETIME ft)

{
long hFT = (((long)ft.dwHighDateTime)
 
Back
Top