Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@Vegar, you can use the <a href="http://msdn.microsoft.com/en-us/library/aa383833%28VS.85%29.aspx" rel="noreferrer">WTSEnumerateSessions</a> and <a href="http://msdn.microsoft.com/en-us/library/aa383838%28VS.85%29.aspx" rel="noreferrer">WTSQuerySessionInformation</a> functions to retrieve this info.</p> <p>check this <a href="http://www.remkoweijnen.nl/blog/2007/10/31/how-to-get-client-ip-address/" rel="noreferrer">link</a> for an example using the <a href="http://blog.delphi-jedi.net/jedi-api-headers/" rel="noreferrer">Jedi Api Headers</a>.</p> <p>check this code.</p> <pre><code>program ProjectTsInfo; {$APPTYPE CONSOLE} Uses Windows, JwaWinType, JwaWtsApi32, JwaWinsock2, SysUtils, TypInfo; type PWtsSessionInfoAArray = ^TWtsSessionInfoAArray; TWtsSessionInfoAArray = array[0..ANYSIZE_ARRAY-1] of WTS_SESSION_INFOA; //Get the info for all clients connected procedure GetAll_TSClientsInfo; var SessionInfoAArray: PWtsSessionInfoAArray; ClientAddr : PWtsClientAddress; ClientName : PAnsiChar; //ClientInfo : PWTSCLIENT; RetBytes : Cardinal; IPAddr : String; i : integer; pCount : Cardinal; SessionId : Cardinal; begin if WtsEnumerateSessions(WTS_CURRENT_SERVER, 0, 1, PWTS_SESSION_INFO(SessionInfoAArray), pCount) then begin for i := 0 to pCount - 1 do begin SessionId:=SessionInfoAArray^[i].SessionId; WTSQuerySessionInformation(WTS_CURRENT_SERVER, SessionId, WTSClientAddress, Pointer(ClientAddr), RetBytes); WTSQuerySessionInformation(WTS_CURRENT_SERVER, SessionId, WTSClientName, Pointer(ClientName), RetBytes); //WTSQuerySessionInformation(WTS_CURRENT_SERVER, SessionId, WTSClientInfo, Pointer(ClientInfo), RetBytes); //This value is supported for Windows Server 2008 and Windows Vista with SP1. try case ClientAddr^.AddressFamily of AF_INET: IPAddr:= Format('%d.%d.%d.%d', [ ClientAddr^.Address[2], ClientAddr^.Address[3], ClientAddr^.Address[4], ClientAddr^.Address[5] ]); else IPAddr:= '&lt;unknow&gt;'; end; WriteLn(Format('Session Id : %d ', [SessionId])); WriteLn(Format('Client Name : %s ', [ClientName])); WriteLn(Format('Station Name: %s ', [SessionInfoAArray^[i].pWinStationName])); WriteLn(Format('State : %s ', [GetEnumName(TypeInfo(WTS_CONNECTSTATE_CLASS),integer(SessionInfoAArray^[i].State))])); WriteLn(Format('IP : %s ', [IPAddr])); //supported for Windows Server 2008 and Windows Vista with SP1. { WriteLn(Format('ClientName : %s ', [ClientInfo^.ClientName])); WriteLn(Format('Domain : %s ', [ClientInfo^.Domain])); WriteLn(Format('UserName : %s ', [ClientInfo^.UserName])); WriteLn(Format('WorkDirectory : %s ', [ClientInfo^.WorkDirectory])); WriteLn(Format('InitialProgram : %s ', [ClientInfo^.InitialProgram])); WriteLn(Format('EncryptionLevel : %d ', [ClientInfo^.EncryptionLevel])); WriteLn(Format('HRes : %d ', [ClientInfo^.HRes])); WriteLn(Format('VRes : %d ', [ClientInfo^.VRes])); WriteLn(Format('ColorDepth : %d ', [ClientInfo^.ColorDepth])); WriteLn(Format('ClientDirectory : %s ', [ClientInfo^.ClientDirectory])); } Writeln(''); finally WTSFreeMemory(ClientAddr); WTSFreeMemory(ClientName); end; end; end; WtsFreeMemory(SessionInfoAArray); end; //Get the ip address of the actual connected client function GetIpActualClient : string; var ClientAddr : PWtsClientAddress; RetBytes : Cardinal; IPAddr : String; SessionId : Cardinal; begin SessionId:=WTS_CURRENT_SESSION; WTSQuerySessionInformation(WTS_CURRENT_SERVER, SessionId, WTSClientAddress, Pointer(ClientAddr), RetBytes); try case ClientAddr^.AddressFamily of AF_INET: IPAddr:= Format('%d.%d.%d.%d', [ ClientAddr^.Address[2], ClientAddr^.Address[3], ClientAddr^.Address[4], ClientAddr^.Address[5] ]); else IPAddr:= '&lt;unknow&gt;'; end; Result:=IPAddr; finally WTSFreeMemory(ClientAddr); end; end; begin Writeln('IP Actual client '+GetIpActualClient); Writeln('-----------------------------------'); GetAll_TSClientsInfo; Readln; end. </code></pre> <p><strong>UPDATE</strong></p> <p>As @Remko says, the <strong>WTSQuerySessionInformation</strong> function with the <strong>WTSClientAddress</strong> type, can return the local IP of the client. if you wanna get the real ip you can use the WinStationGetRemoteIPAddress helper function located in the JwaWinSta unit.</p> <pre><code>Var Port : Word; IpAddr : WideString; Begin WinStationGetRemoteIPAddress(WTS_CURRENT_SERVER,WTS_CURRENT_SESSION,IpAddr,Port); End; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload