You might find the follow useful:
It is the code that I use to find the session name.
Mace
************************************************************
* A new func to return whether the session is a client of terminal services
*************************************************************
PROCEDURE IsTerminalService
LPARAMETERS tlIsTerminalService
DECLARE INTEGER GetSystemMetrics IN User32.dll INTEGER
tlIsTerminalService = ( GetSystemMetrics( 4096) > 0)
CLEAR DLLS
RETURN 0
************************************************************************************************************
* Returns a client service machine name
*
***********************************************************************************************************
PROCEDURE GETWTSClientName
LPARAMETERS tcSessionName
LOCAL lcBuffer, lnReturned, lnBufferPtr
*-- #defines, I listed these for doc purposes only, not all are used
*-- WTS_INFO_CLASS enum
*!* #DEFINE WTSInitialProgram 0
*!* #DEFINE WTSApplicationName 1
*!* #DEFINE WTSWorkingDirectory 2
*!* #DEFINE WTSOEMId 3
*!* #DEFINE WTSSessionId 4
*!* #DEFINE WTSUserName 5
*!* #DEFINE WTSWinStationName 6
*!* #DEFINE WTSDomainName 7
*!* #DEFINE WTSConnectState 8
*!* #DEFINE WTSClientBuildNumber 9
*!* #DEFINE WTSClientName 10
*!* #DEFINE WTSClientDirectory 11
*!* #DEFINE WTSClientProductId 12
*!* #DEFINE WTSClientHardwareId 13
*!* #DEFINE WTSClientAddress 14
*!* #DEFINE WTSClientDisplay 15
*!* #DEFINE WTSClientProtocolType 16
*!* #DEFINE WTS_CURRENT_SERVER_HANDLE 0
*!* #DEFINE WTS_CURRENT_SESSION -1
*-- Declare the DLL's
DECLARE INTEGER WTSQuerySessionInformation In WTSAPI32 ;
INTEGER, ;
INTEGER, ;
INTEGER, ;
INTEGER @, ;
INTEGER @
DECLARE LONG WTSFreeMemory In WTSAPI32 INTEGER
DECLARE INTEGER RtlMoveMemory In Win32API ;
STRING @, ;
INTEGER, ;
INTEGER
lcBuffer = REPL( CHR(0), 1024)
lnReturned = 0
lnBufferPtr = 0
IF WTSQuerySessionInformation( 0, -1, 6, @lnBufferPtr, @lnReturned) = 0
DECLARE INTEGER GetLastError IN Win32API
lnError = GetLastError()
RETURN _ValidError
ENDIF
RtlMoveMemory( @lcBuffer, lnBufferPtr, lnReturned)
WTSFreeMemory( lnBufferPtr)
CLEAR DLLS
tcSessionName = LEFT( lcBuffer, lnReturned - 1)
RETURN 0
>Hello Hugo,
>
>thanks for your help.
>
>I would like to get the machine name of the connected remote client.
>
>WTSEnumerateSessions function retrieves a list of sessions on a specified terminal server. This include the machine name.
>
>There is an example that I am trying to follow, but it is in Visual Basic.
>I am having problems trying to convert VB code to Foxpro.
>Maybe someone knows a URL that provides this conversion service.
>
>Here is the Visual Basic example :
>
http://support.microsoft.com/default.aspx?scid=kb;en-us;291789>
>
>Thanks,
>Sergio