Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

c# - TerminalServicesManager().CurrentSession.ClientName

I am trying to figure out what clients are connected to my machine using remote desktop. I read about Cassia and the Cassia.TerminalServicesManager, but I can't wrap my mind around it...

I thought that Cassia.TerminalServicesManager().CurrentSession.ClientName would give me a name of the client, but what if there are more? I looked at the references, but I am still confused. Can someone help me out?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It sounds like you're looking for something like this:

var manager = new TerminalServicesManager();
using (var server = manager.GetLocalServer())
{
    server.Open();
    foreach (var session in server.GetSessions())
    {
        if (session.ConnectionState == ConnectionState.Active)
        {
            Console.WriteLine(session.ClientName);
        }
    }
}

ITerminalServicesManager.CurrentSession returns the session in which the current process is running.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...