Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get Client, Session in Terminal Server Environmen
Message
De
20/05/2003 08:33:58
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00789972
Message ID:
00790379
Vues:
123
This message has been marked as the solution to the initial question of the thread.
Andreas,

I have misunderstood your question.

Does this work ?
*--------------------------------------------------------------------------
function do_it()

	local SessionId, ClientName, ClientIpAddress 
	
	?GetClientInfo(@SessionId, @ClientName, @ClientIpAddress )
	?'SessionId: ', SessionId
	?'ClientName: ', ClientName
	?'ClientIpAddress: ', ClientIpAddress 
endfunc
*--------------------------------------------------------------------------
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


	declare integer WTSQuerySessionInformation in Wtsapi32.dll ;
		integer hServer, ;
		integer SessionId, ;
		Integer WTSInfoClass, ;
		long @ ppBuffer, ;
		integer @pBytesReturned

	declare WTSFreeMemory in Wtsapi32.dll long address

	local ClientAddress, nBytes, sts, i
	ClientAddress = repl( chr(0), 4 + 20)
	nBytes = 0
	ppBuffer = 0
	
	&& ClientIpAddress 
	sts = WTSQuerySessionInformation( ;
			WTS_CURRENT_SERVER_HANDLE, ;
			WTS_CURRENT_SESSION, ;
			WTSClientAddress, ;
			@ppBuffer, ;
			@nBytes ;
			)

	ClientIpAddress = ''

	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

	&& SessionId 
	sts = WTSQuerySessionInformation( ;
			WTS_CURRENT_SERVER_HANDLE, ;
			WTS_CURRENT_SESSION, ;
			WTSSessionId, ;
			@ppBuffer, ;
			@nBytes ;
			)
	SessionId = 0
	
	do case
	case !empty(sts) 
		declare RtlMoveMemory in win32api long @Dest, long Src, long BytesToCopy
		=RtlMoveMemory( @SessionId , ppBuffer, 4)
		=WTSFreeMemory( ppBuffer )
	endcase
	
	
	&& ClientName
	sts = WTSQuerySessionInformation( ;
			WTS_CURRENT_SERVER_HANDLE, ;
			WTS_CURRENT_SESSION, ;
			WTSClientName, ;
			@ppBuffer, ;
			@nBytes ;
			)
	ClientName = repl(chr(0), 255)
	
	do case
	case !empty(sts) 
		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
	
	
endfunc 
*--------------------------------------------------------------------------
>Gregory,
>
>SYS(0) returns the server computer name. In a Terminal Server
>environment I need the Client's computer name
>(e.g. GETENV("CLIENTNAME") and GETENV("SESSIONNAME").
>Unfortunately environment variables are not save and
>could be set before program start by customers.
>
>Andreas
>
>
>>Andreas,
>>
>>Can the first part of sys(0) be of any help ?
>>
>>Gregory
>>_
>>>Hello,
>>>
>>>I want to limit the number of users/program starts in a
>>>Terminal Server Environment.
>>>
>>>How can I read the Clientname (Computer name) and the
>>>Session ID?
>>>
>>>I know it is in the environmemt (GETENV). But this can be
>>>easily manipulated by our customers (just setting different
>>>values before program start).
>>>
>>>I already tried the registry (Volatile Environment), but these
>>>values will be overwriiten if the same user name logs in twice.
>>>
>>>Any suggestions?
>>>
>>>Thanks in advance.
>>>
>>>Andreas
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform