Skip to content

Commit

Permalink
Fixed incorrect struct layout for WTSINFO (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
dahall committed Feb 24, 2022
1 parent 667ab7c commit 56606c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions PInvoke/WTSApi32/WTSApi32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2955,7 +2955,7 @@ public struct WTSINFO
public uint IncomingCompressedBytes;

/// <summary/>
public uint OutgoingCompressedBy;
public uint OutgoingCompressedBytes;

/// <summary>A null-terminated string that contains the name of the WinStation for the session.</summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = WINSTATIONNAME_LENGTH)]
Expand All @@ -2966,7 +2966,7 @@ public struct WTSINFO
public string Domain;

/// <summary>A null-terminated string that contains the name of the user who owns the session.</summary>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = USERNAME_LENGTH + 1)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = USERNAME_LENGTH + 2)]
public string UserName;

/// <summary>The most recent client connection time.</summary>
Expand Down
14 changes: 14 additions & 0 deletions UnitTests/PInvoke/WTSApi32/WTSApi32Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NUnit.Framework.Internal;
using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using static Vanara.PInvoke.WTSApi32;

namespace Vanara.PInvoke.Tests
Expand All @@ -25,5 +26,18 @@ public void WTSEnumerateServersTest()
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)
{
Assert.That(WTSQuerySessionInformation(HWTSSERVER.WTS_CURRENT_SERVER_HANDLE, session.SessionId, WTS_INFO_CLASS.WTSSessionInfo, out var pSessionInfo, out var size), ResultIs.Successful);
Assert.That(Marshal.SizeOf<WTSINFO>(), Is.EqualTo((int)size));
var si = pSessionInfo.ToStructure<WTSINFO>(size);
TestContext.WriteLine($"{si.WinStationName} : {si.CurrentTime.ToDateTime()}");
}
}
}
}

0 comments on commit 56606c0

Please sign in to comment.