Solved

Get the Client ip address using wtsapi32.dll and WTSQuerySessionInformation

Posted on 2002-07-11
8
1,924 Views
Last Modified: 2007-11-27
Hello All
I an urgently looking for an example of using WTSQuerySessionInformation to get the IP address of the current session on a Terminal Server.
Thanks
Dean.
0
Comment
Question by:Dwhite
  • 6
8 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 500 total points
ID: 7145749
If you need declaration, then here it is

Public Declare Function WTSQuerySessionInformation _
        Lib "wtsapi32.dll" Alias "WTSQuerySessionInformationA" ( _
        ByVal hServer As Long, ByVal SessionID As Long, _
        ByVal pWTSInfoClass As WTS_INFO_CLASS, ByRef ppSessionInfo As Long, _
        ByRef pBytesReturned As Long _
        ) As Boolean
     
    WTS_INFO_CLASS
    Public Enum WTS_INFO_CLASS
         WTSInitialProgram
         WTSApplicationName
         WTSWorkingDirectory
         WTSOEMId
         WTSSessionId
         WTSUserName
         WTSWinStationName
         WTSDomainName
         WTSConnectState
         WTSClientBuildNumber
         WTSClientName
         WTSClientDirectory
         WTSClientProductId
         WTSClientHardwareId
         WTSClientAddress
         wtsClientDisplay
    End Enum
     
    Public Enum WTS_CONNECTSTATE_CLASS
        WTSActive
        WTSConnected
        WTSConnectQuery
        WTSShadow
        WTSDisconnected
        WTSIdle
        WTSListen
        WTSReset
        WTSDown
        WTSInit
    End Enum
     
Good Luck
0
 

Author Comment

by:Dwhite
ID: 7145765
Thaks a lot roshmon

do you have an example of how to call it for the current session.
Thanks
Dean
0
 
LVL 1

Expert Comment

by:PX
ID: 7145847
Here you go, this is the link with a example on how tou use wtsquerysessioninformation.

http://a1network.net/downloads/WTSobjs.zip

PX
0
 

Author Comment

by:Dwhite
ID: 7146264
Thank you PX
This does not show me how to make the API Call as it is already compiled into a Dll.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Dwhite
ID: 7146402
Points increase to 500
Please help
0
 

Author Comment

by:Dwhite
ID: 7148833
I'm in trouble here
This Executes but returns Rubbish
I have increased the points to 1000

Public Function QueryUserConfig() As String
   
    Dim bufPtr      As Long
    Dim bufLen      As Long
    Dim tmpStr()    As Byte
    Dim idx         As Integer

On Error GoTo ERR_QueryUserConfig

    CTXQueryUserConfig = False
    cSvrName = svrName & vbNullChar
    cUsrName = userName & vbNullChar
    If WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientAddress, bufPtr, bufLen) Then
        If bufLen > 0 Then
            ReDim tmpStr(bufLen)
            Call CopyMemory(tmpStr(0), bufPtr, bufLen)
            For idx = 0 To bufLen
                'retString = retString & Chr$(tmpStr(idx))
                retString = retString & tmpStr(idx)
            Next idx
           
            Erase tmpStr
        End If
        Call WTSFreeMemory(bufPtr)
        QueryUserConfig = retString
    End If
    Exit Function
   
ERR_QueryUserConfig:
    Exit Function
End Function
0
 

Author Comment

by:Dwhite
ID: 7148839
OK so I cant Increase the Points but I will create another question for 500 for the Example that works.
0
 

Author Comment

by:Dwhite
ID: 7164149
I have since found out how to do this and your response pointed me in the right direction so thanks a lot.
Dean White.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now