I just wrote a program in C# that does that. There's a lot of code out
there for this particular function in VB6 and VB.NET/C#.NET. Just do a
search for source code using the WTS API (WTSAPI32.DLL). The main functions
you're looking for are WTSEnumerateServers() and WTSEnumerateSessions().
Check out this MS KB article to start: http://support.microsoft.com/default.aspx?scid=KB;[LN];Q291789.