Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2098
  • Last Modified:

Get the Client ip address using wtsapi32.dll and WTSQuerySessionInformation

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
Dwhite
Asked:
Dwhite
  • 6
1 Solution
 
Roshan DavisCommented:
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
 
DwhiteAuthor Commented:
Thaks a lot roshmon

do you have an example of how to call it for the current session.
Thanks
Dean
0
 
PXCommented:
Here you go, this is the link with a example on how tou use wtsquerysessioninformation.

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

PX
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DwhiteAuthor Commented:
Thank you PX
This does not show me how to make the API Call as it is already compiled into a Dll.
0
 
DwhiteAuthor Commented:
Points increase to 500
Please help
0
 
DwhiteAuthor Commented:
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
 
DwhiteAuthor Commented:
OK so I cant Increase the Points but I will create another question for 500 for the Example that works.
0
 
DwhiteAuthor Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now