>local SessionId, ClientName, ClientIpAddress >ExecutingOnTS = GetClientInfo(@SessionId, @ClientName, @ClientIpAddress ) and !empty(ClientIpAddress) >>
>*--------------------------------------------------------------------------- >function do_it() > > local SessionId, ClientName, ClientIpAddress > > ?GetClientInfo(@SessionId, @ClientName, @ClientIpAddress ) > ?'SessionId: ', SessionId > ?'ClientName: ', ClientName > ?'ClientIpAddress: ', ClientIpAddress >endfunc >*-------------------------------------------------------------------------- >#IFNDEF TRUE > #define TRUE .T. > #define FALSE .F. > > #define MAX_INTEGER (0x7fffffff) >#ENDIF > >function GetClientInfo(SessionId, ClientName, ClientIpAddress ) > >#define WTS_CURRENT_SERVER_HANDLE (0) >#define WTS_CURRENT_SESSION (-1) > >#define WTSSessionId (4) >#define WTSClientName (10) >#define WTSClientAddress (14) > >#ifndef AF_INET >#define AF_INET 2 >#endif > > local Success > Success = TRUE > > local sError > sError = on('error') > on error Success = FALSE > > declare integer WTSQuerySessionInformation in Wtsapi32.dll ; > integer hServer, ; > integer SessionId, ; > Integer WTSInfoClass, ; > long @ ppBuffer, ; > integer @pBytesReturned > > declare WTSFreeMemory in Wtsapi32.dll long address > on error &sError > > SessionId = 0 > ClientName = '' > ClientIpAddress = '' > > local ClientAddress, nBytes, sts, i > ClientAddress = repl( chr(0), 4 + 20) > nBytes = 0 > ppBuffer = 0 > > do case > case !Success > > otherwise > && ClientIpAddress > sts = WTSQuerySessionInformation( ; > WTS_CURRENT_SERVER_HANDLE, ; > WTS_CURRENT_SESSION, ; > WTSClientAddress, ; > @ppBuffer, ; > @nBytes ; > ) > > do case > case !empty(sts) > declare RtlMoveMemory in win32api string @Dest, long Src, long BytesToCopy > =RtlMoveMemory( @ClientAddress, ppBuffer, nBytes) > =WTSFreeMemory( ppBuffer ) > > do case > case left(ClientAddress,1) == chr(AF_INET) > for i = 7 to 7+ 3 > ClientIpAddress = ClientIpAddress + iif(empty(ClientIpAddress), '', '.') + transform(asc(substr(ClientAddress, i, 1))) > endfor > endcase > > endcase > > endcase > > do case > case !Success > > otherwise > && SessionId > sts = WTSQuerySessionInformation( ; > WTS_CURRENT_SERVER_HANDLE, ; > WTS_CURRENT_SESSION, ; > WTSSessionId, ; > @ppBuffer, ; > @nBytes ; > ) > > > do case > case !empty(sts) > declare RtlMoveMemory in win32api long @Dest, long Src, long BytesToCopy > =RtlMoveMemory( @SessionId , ppBuffer, 4) > =WTSFreeMemory( ppBuffer ) > endcase > > endcase > > do case > case !Success > > otherwise > && ClientName > sts = WTSQuerySessionInformation( ; > WTS_CURRENT_SERVER_HANDLE, ; > WTS_CURRENT_SESSION, ; > WTSClientName, ; > @ppBuffer, ; > @nBytes ; > ) > ClientName = repl(chr(0), 255) > > do case > case !empty(sts) and !empty(ppBuffer) > declare RtlMoveMemory in win32api string @Dest, long Src, long BytesToCopy > =RtlMoveMemory( @ClientName, ppBuffer, len(ClientName)) > =WTSFreeMemory( ppBuffer ) > ClientName = left(ClientName, at(chr(0), ClientName)-1) > > otherwise > ClientName = '' > endcase > endcase > > return Success > >endfunc >*-------------------------------------------------------------------------- >