mirror of https://github.com/dahall/Vanara.git
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
parent
667ab7cdad
commit
83f899a665
|
@ -3,7 +3,6 @@ using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Vanara.Extensions;
|
using Vanara.Extensions;
|
||||||
using Vanara.InteropServices;
|
using Vanara.InteropServices;
|
||||||
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
|
|
||||||
|
|
||||||
namespace Vanara.PInvoke
|
namespace Vanara.PInvoke
|
||||||
{
|
{
|
||||||
|
@ -1103,7 +1102,7 @@ namespace Vanara.PInvoke
|
||||||
|
|
||||||
/// <summary>Retrieves the child session identifier, if present.</summary>
|
/// <summary>Retrieves the child session identifier, if present.</summary>
|
||||||
/// <param name="pSessionId">
|
/// <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.
|
/// child session for the current session.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>Returns nonzero if the function succeeds or zero otherwise.</returns>
|
/// <returns>Returns nonzero if the function succeeds or zero otherwise.</returns>
|
||||||
|
@ -1684,7 +1683,7 @@ namespace Vanara.PInvoke
|
||||||
/// </para>
|
/// </para>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// If <c>FALSE</c>, the function returns immediately and the pResponse parameter returns <c>IDASYNC</c>. Use this method for simple
|
/// 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 job–notification messages) that do not need to return the user's response to the calling program.
|
/// information messages (such as print job–notification messages) that do not need to return the user's response to the calling program.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
|
@ -2970,19 +2969,34 @@ namespace Vanara.PInvoke
|
||||||
public string UserName;
|
public string UserName;
|
||||||
|
|
||||||
/// <summary>The most recent client connection time.</summary>
|
/// <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>
|
/// <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>
|
/// <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>
|
/// <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>
|
/// <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>
|
/// <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
|
/// 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).
|
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time (Greenwich Mean Time).
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// The time of the most recent client connection to the session. This value is stored as a large integer that represents the
|
/// 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.
|
/// number of 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// The time of the most recent client disconnection to the session. This value is stored as a large integer that represents the
|
/// 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.
|
/// number of 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// The time of the last user input in the session. This value is stored as a large integer that represents the number of
|
/// 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.
|
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// The time that this structure was filled. This value is stored as a large integer that represents the number of
|
/// 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.
|
/// 100-nanosecond intervals since January 1, 1601 Coordinated Universal Time.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// The number of bytes of uncompressed Remote Desktop Protocol (RDP) data sent from the client to the server since the client connected.
|
/// The number of bytes of uncompressed Remote Desktop Protocol (RDP) data sent from the client to the server since the client connected.
|
||||||
|
|
|
@ -25,5 +25,64 @@ namespace Vanara.PInvoke.Tests
|
||||||
Assert.That(WTSEnumerateServers(null, out var servers), ResultIs.Successful);
|
Assert.That(WTSEnumerateServers(null, out var servers), ResultIs.Successful);
|
||||||
servers.WriteValues();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue