|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Determining IP of client in Windows Terminal Server, .NETa client that has connected into a terminal services server. IE, the user would be logged into the server, and they would run an app that would like to know the ip address that they're connecting from. I really need the solution to work in a .NET app (VB). I've seen the tons of sample code out there for WTSQuerySessionInformation, but no matter what I do I can't seem to get it to run in VB.NET.... In particular, when I run this code, Dim joe As New System.IntPtr Dim bytes As New UInteger Dim pp As New WtsApi32.WtsClientAddress Dim t As Boolean = WtsApi32.NativeMethods.WtsQuerySessionInformation(0, -1, WtsInfoClass.WtsClientAddress, joe, bytes) pp = CType(Marshal.PtrToStructure(joe, GetType(WtsApi32.WtsClientAddress)), WtsApi32.WtsClientAddress) bla = pp.Address(2) & "." & pp.Address(3) & "." & pp.Address(4) & "." & pp.Address I get an error assigning PP, "AccessViolationException" I'm using .NET 2.0 - is any of this found in native .NET code? If not, can anyone help me out? gr***@ids.net wrote:
Show quote > Hey there - I'm looking for a working solution to get the IP address of Please post the declare for WtsQuerySessionInformation..> a client that has connected into a terminal services server. > > IE, the user would be logged into the server, and they would run an app > that would like to know the ip address that they're connecting from. > > I really need the solution to work in a .NET app (VB). > > I've seen the tons of sample code out there for > WTSQuerySessionInformation, but no matter what I do I can't seem to get > it to run in VB.NET.... > > In particular, when I run this code, > > Dim joe As New System.IntPtr > Dim bytes As New UInteger > > Dim pp As New WtsApi32.WtsClientAddress > > Dim t As Boolean = > WtsApi32.NativeMethods.WtsQuerySessionInformation(0, -1, > WtsInfoClass.WtsClientAddress, joe, bytes) > pp = CType(Marshal.PtrToStructure(joe, > GetType(WtsApi32.WtsClientAddress)), WtsApi32.WtsClientAddress) > bla = pp.Address(2) & "." & pp.Address(3) & "." & pp.Address(4) > & "." & pp.Address > > I get an error assigning PP, "AccessViolationException" > > I'm using .NET 2.0 - is any of this found in native .NET code? If not, > can anyone help me out? -- Tom Shelton Here's what I've got...
Private Declare Function WTSQuerySessionInformation Lib "wtsapi32.dll" _ Alias "WTSQuerySessionInformationA" (ByVal hServer As Long, _ ByVal SessionID As Integer, ByVal WTS_INFO_CLASS As WTSInfoClass, _ ByRef QSbuffer As Integer, ByRef pCount As Integer) As Long You may have just konked me in the head to show me where my problem was - but just in case, I'll ask directly - do you see a problem in the declaration/usage, perhaps? :-) (Thanks a ton!) Tom Shelton wrote: Show quote > gr***@ids.net wrote: > > Hey there - I'm looking for a working solution to get the IP address of > > a client that has connected into a terminal services server. > > > > IE, the user would be logged into the server, and they would run an app > > that would like to know the ip address that they're connecting from. > > > > I really need the solution to work in a .NET app (VB). > > > > I've seen the tons of sample code out there for > > WTSQuerySessionInformation, but no matter what I do I can't seem to get > > it to run in VB.NET.... > > > > In particular, when I run this code, > > > > Dim joe As New System.IntPtr > > Dim bytes As New UInteger > > > > Dim pp As New WtsApi32.WtsClientAddress > > > > Dim t As Boolean = > > WtsApi32.NativeMethods.WtsQuerySessionInformation(0, -1, > > WtsInfoClass.WtsClientAddress, joe, bytes) > > pp = CType(Marshal.PtrToStructure(joe, > > GetType(WtsApi32.WtsClientAddress)), WtsApi32.WtsClientAddress) > > bla = pp.Address(2) & "." & pp.Address(3) & "." & pp.Address(4) > > & "." & pp.Address > > > > I get an error assigning PP, "AccessViolationException" > > > > I'm using .NET 2.0 - is any of this found in native .NET code? If not, > > can anyone help me out? > > Please post the declare for WtsQuerySessionInformation.. > > -- > Tom Shelton gr***@ids.net wrote:
> Here's what I've got... Yes, actually I do:> > Private Declare Function WTSQuerySessionInformation Lib > "wtsapi32.dll" _ > Alias "WTSQuerySessionInformationA" (ByVal hServer As Long, _ > ByVal SessionID As Integer, ByVal WTS_INFO_CLASS As > WTSInfoClass, _ > ByRef QSbuffer As Integer, ByRef pCount As Integer) As Long > > > You may have just konked me in the head to show me where my problem was > - but just in case, I'll ask directly - do you see a problem in the > declaration/usage, perhaps? :-) Private Declare Auto Function WTSQuerySessionInformation Lib "wtsapi32" ( _ ByVal hServer As IntPtr, _ ByVal SessionId As Integer, _ ByVal WTSInfoClass As WTS_INFO_CLASS, _ ByRef ppBuffer As IntPtr, _ ByRef pBytesReturned As Integer) As Boolean |
|||||||||||||||||||||||