Correct alignment for WTSINFO and WTSINFOEX. (#279)

Thanks for your replies. I'm convinced. I'll merge. Thanks for your input and contributions.
pull/280/head
NN 2022-02-25 20:13:16 +02:00 committed by GitHub
parent 667ab7cdad
commit 83f899a665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 116 additions and 13 deletions

View File

@ -3,7 +3,6 @@ using System.Runtime.InteropServices;
using System.Text;
using Vanara.Extensions;
using Vanara.InteropServices;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
namespace Vanara.PInvoke
{
@ -1103,7 +1102,7 @@ namespace Vanara.PInvoke
/// <summary>Retrieves the child session identifier, if present.</summary>
/// <param name="pSessionId">
/// The address of a <c>ULONG</c> variable that receives the child session identifier. This will be ( <c>ULONG</c>)1 if there is no
/// The address of a <c>ULONG</c> variable that receives the child session identifier. This will be ( <c>ULONG</c>)1 if there is no
/// child session for the current session.
/// </param>
/// <returns>Returns nonzero if the function succeeds or zero otherwise.</returns>
@ -1684,7 +1683,7 @@ namespace Vanara.PInvoke
/// </para>
/// <para>
/// If <c>FALSE</c>, the function returns immediately and the pResponse parameter returns <c>IDASYNC</c>. Use this method for simple
/// information messages (such as print jobnotification messages) that do not need to return the user's response to the calling program.
/// information messages (such as print jobnotification messages) that do not need to return the user's response to the calling program.
/// </para>
/// </param>
/// <returns>
@ -2970,19 +2969,34 @@ namespace Vanara.PInvoke
public string UserName;
/// <summary>The most recent client connection time.</summary>
public FILETIME ConnectTime;
public long ConnectTimeUTC;
/// <summary>The most recent client connection time.</summary>
public DateTime ConnectTime => DateTime.FromFileTimeUtc(ConnectTimeUTC);
/// <summary>The last client disconnection time.</summary>
public FILETIME DisconnectTime;
public long DisconnectTimeUTC;
/// <summary>The last client disconnection time.</summary>
public DateTime DisconnectTime => DateTime.FromFileTimeUtc(DisconnectTimeUTC);
/// <summary>The time of the last user input in the session.</summary>
public FILETIME LastInputTime;
public long LastInputTimeUTC;
/// <summary>The time of the last user input in the session.</summary>
public DateTime LastInputTime => DateTime.FromFileTimeUtc(LogonTimeUTC);
/// <summary>The time that the user logged on to the session.</summary>
public FILETIME LogonTime;
public long LogonTimeUTC;
/// <summary>The time that the user logged on to the session.</summary>
public DateTime LogonTime => DateTime.FromFileTimeUtc(LogonTimeUTC);
/// <summary>The time that the <c>WTSINFO</c> data structure was called.</summary>
public FILETIME CurrentTime;
public long CurrentTimeUTC;
/// <summary>The time that the <c>WTSINFO</c> data structure was called.</summary>
public DateTime CurrentTime => DateTime.FromFileTimeUtc(CurrentTimeUTC);
}
/// <summary>
@ -3066,31 +3080,61 @@ namespace Vanara.PInvoke
/// The time that the user logged on to the session. This value is stored as a large integer that represents the number of
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time (Greenwich Mean Time).
/// </summary>
public FILETIME LogonTime;
public long LogonTimeUTC;
/// <summary>
/// The time that the user logged on to the session. This value is stored as a large integer that represents the number of
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time (Greenwich Mean Time).
/// </summary>
public DateTime LogonTime => DateTime.FromFileTimeUtc(LogonTimeUTC);
/// <summary>
/// The time of the most recent client connection to the session. This value is stored as a large integer that represents the
/// number of 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
/// </summary>
public FILETIME ConnectTime;
public long ConnectTimeUTC;
/// <summary>
/// The time of the most recent client connection to the session. This value is stored as a large integer that represents the
/// number of 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
/// </summary>
public DateTime ConnectTime => DateTime.FromFileTimeUtc(ConnectTimeUTC);
/// <summary>
/// The time of the most recent client disconnection to the session. This value is stored as a large integer that represents the
/// number of 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
/// </summary>
public FILETIME DisconnectTime;
public long DisconnectTimeUTC;
/// <summary>
/// The time of the most recent client disconnection to the session. This value is stored as a large integer that represents the
/// number of 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
/// </summary>
public DateTime DisconnectTime => DateTime.FromFileTimeUtc(DisconnectTimeUTC);
/// <summary>
/// The time of the last user input in the session. This value is stored as a large integer that represents the number of
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
/// </summary>
public FILETIME LastInputTime;
public long LastInputTimeUTC;
/// <summary>
/// The time of the last user input in the session. This value is stored as a large integer that represents the number of
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
/// </summary>
public DateTime LastInputTime => DateTime.FromFileTimeUtc(LastInputTimeUTC);
/// <summary>
/// The time that this structure was filled. This value is stored as a large integer that represents the number of
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
/// </summary>
public FILETIME CurrentTime;
public long CurrentTimeUTC;
/// <summary>
/// The time that this structure was filled. This value is stored as a large integer that represents the number of
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
/// </summary>
public DateTime CurrentTime => DateTime.FromFileTimeUtc(CurrentTimeUTC);
/// <summary>
/// The number of bytes of uncompressed Remote Desktop Protocol (RDP) data sent from the client to the server since the client connected.

View File

@ -25,5 +25,64 @@ namespace Vanara.PInvoke.Tests
Assert.That(WTSEnumerateServers(null, out var servers), ResultIs.Successful);
servers.WriteValues();
}
[Test]
public void WTSEnumerateSessionsExTest()
{
Assert.That(WTSEnumerateSessionsEx(HWTSSERVER.WTS_CURRENT_SERVER_HANDLE, out var sessionList),
ResultIs.Successful);
foreach (var session in sessionList)
{
if (WTSQuerySessionInformation(
HWTSSERVER.WTS_CURRENT_SERVER_HANDLE,
session.SessionId,
WTS_INFO_CLASS.WTSSessionInfo,
out var pSessionInfo,
out var bytesReturned))
{
using (pSessionInfo)
{
var wtsInfo = pSessionInfo.ToStructure<WTSINFO>(bytesReturned);
Assert.That(() => _ = wtsInfo.SessionId, Throws.Nothing);
Assert.That(() => _ = wtsInfo.UserName, Throws.Nothing);
Assert.That(() => _ = wtsInfo.CurrentTime, Throws.Nothing);
Assert.That(() => _ = wtsInfo.ConnectTime, Throws.Nothing);
Assert.That(() => _ = wtsInfo.LastInputTime, Throws.Nothing);
}
}
}
}
[Test]
public void WTSEnumerateSessionsExSessionInfoExTest()
{
Assert.That(WTSEnumerateSessionsEx(HWTSSERVER.WTS_CURRENT_SERVER_HANDLE, out var sessionList),
ResultIs.Successful);
foreach (var session in sessionList)
{
if (WTSQuerySessionInformation(
HWTSSERVER.WTS_CURRENT_SERVER_HANDLE,
session.SessionId,
WTS_INFO_CLASS.WTSSessionInfoEx,
out var pSessionInfo,
out var bytesReturned))
{
using (pSessionInfo)
{
var wtsInfoEx = pSessionInfo.ToStructure<WTSINFOEX>(bytesReturned);
if (wtsInfoEx.Level == 1)
{
Assert.That(() => _ = wtsInfoEx.Data.WTSInfoExLevel1.SessionId, Throws.Nothing);
Assert.That(() => _ = wtsInfoEx.Data.WTSInfoExLevel1.UserName, Throws.Nothing);
Assert.That(() => _ = wtsInfoEx.Data.WTSInfoExLevel1.CurrentTime, Throws.Nothing);
Assert.That(() => _ = wtsInfoEx.Data.WTSInfoExLevel1.ConnectTime, Throws.Nothing);
Assert.That(() => _ = wtsInfoEx.Data.WTSInfoExLevel1.LastInputTime, Throws.Nothing);
}
}
}
}
}
}
}