Question: [This question](https://stackoverflow.com/questions/159910/determine-if-a-program-is-running-on-a-remote-desktop) tells me how to detect a remote desktop session.

Do anybody know if it's possible to find out from where the remote connection was initialized?

Answer: 
For me, this worked, it gets the name of the machine connected.

```
Environment.GetEnvironmentVariable("CLIENTNAME")

```
WTSQuerySessionInformation returns the client IP as the client reports it, this will probably be (one) of it's local IP Address. If you want to know the REAL ip address and port that is connected you can use WinStationQueryInformationW with information class WinStationRemoteAddress.
You will need my unit JwaWinsta from the Jedi Apilib.

I have provided a simple wrapper in the same unit as well:

```
function WinStationGetRemoteIPAddress(hServer: HANDLE; SessionId: DWORD;
  var RemoteIPAddress: WideString; var Port: WORD): Boolean;

```