Call the WTSQuerySessionInformation function in the TS API using the
WTSClientAddress member of the WtsInfoClass enum for the type you want; it
will return an array of 20 bytes, and I believe bytes 5-8 will contain the
IP data.
You can check my website (referenced at bottom) for some info; also the
following for info from Microsoft.
http://www.microsoft.com/ntserver/docs/TseApis.doc
http://msdn.microsoft.com/library/en-us/termserv/termserv/wtsquerysessioninformation.asp
http://msdn.microsoft.com/library/en-us/termserv/termserv/wts_info_class_str.asp
Below is some VB code I put together a while back for this...
Private Type WTS_CLIENT_ADDRESS
ADDRESSFAMILY As Long
' Address family. This member can be AF_INET, AF_IPX, AF_NETBIOS, or
AF_UNSPEC
ADDRESS(20) As Byte
' Client network address
End Type
Private Enum WTS_INFO_CLASS
WTSInitialProgram
WTSApplicationName
WTSWorkingDirectory
WTSOEMId
WTSSessionId
WtsUserName
WTSWinStationName
WTSDomainName
WTSConnectState
WTSClientBuildNumber
WTSClientName
WTSClientDirectory
WTSClientProductId
WTSClientHardwareId
WtsClientAddress
WTSClientDisplay
WTSClientProtocolType
End Enum
Private Const WTS_CURRENT_SERVER = 0&
Private Const WTS_CURRENT_SERVER_HANDLE = 0&
Private Declare Function WTSQuerySessionInformation Lib "wtsapi32" _
Alias "WTSQuerySessionInformationW" (ByVal hServer As Long, _
ByVal SessionID As Long, ByVal wtsInfoClass As WTS_INFO_CLASS, _
ByRef ppBuffer As Long, ByRef pBytesReturned As Long) As Long
Private Declare Sub WTSFreeMemory Lib "wtsapi32" ( _
ByVal pMemory As Long)
Private Declare Sub RtlMoveMemory Lib "kernel32" ( _
pTo As Any, ByVal uFrom As Any, ByVal lSize As Long)
Public Function Ptr_PtrToString(ByVal lpStr As Long, _
ByVal lStrLen As Long) As String
Dim sBuffer As String
' Fill buffer with null characters
sBuffer = String(lStrLen, Chr(0))
RtlMoveMemory ByVal sBuffer, ByVal lpStr, ByVal Len(sBuffer)
Ptr_PtrToString = Replace(sBuffer, Chr(0), "")
End Function
Public function IpAddress(ByVal SessionID As Long) As String
Dim lRet As Long
Dim wca_Tmp As WTS_CLIENT_ADDRESS
Dim pBytesReturned As Long
Dim ppBuffer As Long
lRet = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, _
SessionID, WtsClientAddress, ppBuffer, pBytesReturned)
IpAddress = ""
If lRet Then
RtlMoveMemory wca_Tmp, ppBuffer, pBytesReturned
WTSFreeMemory ppBuffer
IpAddress = Join(Array(wca_Tmp.ADDRESS(2), wca_Tmp.ADDRESS(3), _
wca_Tmp.ADDRESS(4), wca_Tmp.ADDRESS(5)), ".")
End If
End Property
--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com
(email requests for support contract information welcomed)
----------
Microsoft's new UNIFIED Terminal Services Newsgroup:
news:microsoft.public.windows.terminal_services