Search code examples
vb.netterminal-services

Hooking into Terminal Services Manager


Has anyone ever come across a way of a way to create an app that kind of mimics what Terminal Services manager does in Windows2003/XP.

I would like to write something that would either go and query a farm of server every n secs a get me a list of users logged in, there process's etc or do maybe type a username in and it goes and finds the user in the farm and returns their details.

Cheers Luke


Solution

  • I would suggest using Cassia, a .NET library which uses internally the Wtsapi32 library Arnshea mentioned. For example, to list all users logged into a server:

    Dim manager As New TerminalServicesManager()
    Using server As ITerminalServer = manager.GetRemoteServer("your-server-name")
        server.Open()
        For Each session As ITerminalServicesSession In server.GetSessions()
            If Not string.IsNullOrEmpty(session.UserName) Then Console.WriteLine(session.UserName)
        Next
    End Using