i am trying to get ip address of remote desktop user. i use code
posted by Willy Denoyette[MVP], which uses wtsapi32 and queries
session information (WTSQuerySessionInformation). as far as i can see
it is possible to get remote address if i pass
WTSInfoClass.ClientAddress as WTS_INFO_CLASS parameter to
WTSQuerySessionInformation. but my problem is lack of c,c++ knowledge
to finish this. now i am completely stuck with this.
as i see, i need to define c# struct which would mimic
_WTS_CLIENT_ADDRESS {
DWORD AddressFamily;
BYTE Addrss[20]
}
how does it look like in c#? i have no clue how to translate dword or
array pointer to c#.
after that i need to
WTSQuerySessionInformation(srv,WTSsi.SessionID,
(int)WTSInfoClass.ClientAddress, ref ppBuffer, ref bCount));
//now ppBuffer is supposed to be pointer to my struct
WTSClientAddress adr = (WTSClientAddress)
Marshal.PtrToStructure(pInfo,typeof(WTSClientAddress));
Console.WriteLine("Adr: {0}",adr.Address);
this was plain guessing and it doesn't work at all!
could anyone please help with this?
thanks for any answer!
dario
[StructLayout(LayoutKind.Sequential)]
struct WtsClientAddress
{
public int AddressFamily;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=20)]
public byte[] Address;
}
....
WTSQuerySessionInformation(hServer, (int)WTSpi.SessionId, 14, ref
ppBuffer, ref bytes);
WtsClientAddress WtsCa = (WtsClientAddress)
Marshal.PtrToStructure(ppBuffer, typeof(WtsClientAddress) );
....
IP address is at offset 2 of the byte array returned in Address.
Willy.
>i am trying to get ip address of remote desktop user. i use code
> posted by Willy Denoyette[MVP], which uses wtsapi32 and queries
[quoted text clipped - 31 lines]
>
> dario
ndario - 15 Apr 2004 11:28 GMT
> WtsClientAddress WtsCa = (WtsClientAddress)
> Marshal.PtrToStructure(ppBuffer, typeof(WtsClientAddress) );
> ....
> IP address is at offset 2 of the byte array returned in Address.
>
> Willy.
Willy, thank you very much for your help, it worked!
now, could you please help with something else...
i need client address in order to send some data to client. there is
TcpListener at client end and it waits for connection from server, and
then server sends some pdf to client to print it on clinet computer. i
am able to determine client address from WTSSession using
ProcessIdToSessionId and then send pdf through the socket to the
client. i am interested is there any better way to do this? i saw that
there are VirtualChannels but i am not sure how to work with them.
would VirtualChannels do better? how you got any suggestions on the
"remote printing"?
thank you
dario
DotNetJunkies User - 04 Aug 2004 18:42 GMT
Dario,
How did you define your API call?
---
DotNetJunkies User - 04 Aug 2004 19:19 GMT