Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / August 2004

Tip: Looking for answers? Try searching our database.

[WTS] remote user address

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ndario - 14 Apr 2004 12:59 GMT
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
Willy Denoyette [MVP] - 14 Apr 2004 15:10 GMT
[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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.