MachineName for remote machine using Remote Deskto

2019-04-14 03:47发布

问题:

I'm writing a C# program where it would be useful to see if someone is running the program via remote desktop and if so, the machine name where the remote desktop is running.

I can get the former using SystemInformation.TerminalServerSession

But is there any way to get the name of the remote machine?

回答1:

I think the Remote Desktop Services API will do what you want... http://msdn.microsoft.com/en-us/library/aa383468(v=VS.85).aspx

And the following example may help too - http://community.citrix.com/display/xa/How+to+get+client+IP+address+and+client+hostname+using+Terminal+Services+API



回答2:

You can certainly use WTSQuerySessionInformation to get this information, though if you'd prefer not to deal with the P/Invokes, you could also use the Cassia library: new TerminalServicesManager().CurrentSession.ClientName.