Dynamic virtual channels

Source: Internet
Author: User
Document directory
  • DVC Basics
  • Sample: ts-teleport

 

Http://www.brianmadden.com/news/43

Http://blogs.msdn.com/ts/pages/ts-teleport-sample-instructions.aspx

 

Http://www.codeproject.com/KB/system/TSAddinInCS.aspx

 

An important goal of the Terminal Services (TS) team is to provide a product that can easily be extended by third parties to better meet their needs. while TS has always supported virtual channels, they had their limitations, including the limited number of channels and the difficulty involved in writing virtual channel applications. for the 6.1 version of the client, and Windows Vista SP1 or Windows Server 2008 on the server side, dynamic virtual channels (DVCs) can be used. DVCs address the limitations of the old virtual channels. this article outlines the basics of DVCs and shows how to write a complete DVC Application and client plug-in to add basic file transfer support to Terminal Services.

DVC basicswhat are virtual channels?

Virtual channels are bi-directional connection streams provided through the RDP protocol. virtual channels allow third parties to establish a data pipe between the TS client and server to extend the functionality of the Remote Desktop Protocol (RDP ). examples of extra functionality provided through virtual channels are cross-ts-connection clipboard, drive, printer and Smart Card redirection. there are two types of virtual channels: static and dynamic. due to the limitations of static virtual channels referenced above, dynamic virtual channels are the preferred way to extend ts functionality.

Client and server DVC Components

On the TS client side the DVC is handled through a TS client plug-in. this plug-in is a COM Object, whose registered CLSID is passed to the TS client through the registry (see the attached sample ). the COM object must implementIwtspluginInterface. on the server side any arbitrary component running in the current session can use the wts api to establish the DVC connection, as well as send and receive data.

Channel initialization and usageclient side

1) The ts client loads the DVC plug-ins from the registry:

Hkcu/software/Microsoft/Terminal Server Client/default/addins

2) The ts client invokes the initialize () method onIwtsplugin; And passesIwtsvirtualchannelmanager

Hresult ctsclientplgn: Initialize (

Iwtsvirtualchannelmanager * pchannelmgr

)

3) during initialization, or at any arbitrary point, the plug-in is expected to useIwtsvirtualchannelmanagerTo create a connection listener and passIwtslistenercallback

HR = pchannelmgr-> createlistener (tstele_channel_name,

0,

Plistenercallback,

& Plistener );

4)IwtslistenercallbackIs notified of connection requests on the channel;IwtslistenercallbackEsIwtsvirtualchannelFor every new connection and returns a correspondingIwtsvirtualchannelcallback

Hresult ctslistenercallback: onnewchannelconnection (

Iwtsvirtualchannel * pchannel,

BSTR data,

Bool * pbaccept,

Iwtsvirtualchannelcallback ** ppcallback)

{

* Pbaccept = true;

_ Pchannelcallback-> addref ();

* Ppcallback = _ pchannelcallback;

Pchannel-> addref ();

_ Pchannel = pchannel;

5) The plug-in usesIwtsvirtualchannelTo write to and close the channel

HR = _ pchannel-> write (sizeof (hresult), (pbyte) & HR, null );

HR = _ pchannel-> close ();

6) The plug-in between es incoming data and channel close communications onIwtsvirtualchannelcallback

Hresult ctschannelcallback: ondatareceived (

Ulong cbsize,

Byte * pbuffer

);

Hresult ctschannelcallback: onclose ();

Server Side

1) An application issuesWtsvirtualchannelopenexWith the wts_channel_option_dynamic flag to establish the DVC connection.

Hwtshandle = wtsvirtualchannelopenex (

Wts_current_session,

Tstele_channel_name,

Wts_channel_option_dynamic );

2) using the WTS handle stored ed from the previous callWtsvirtualchannelqueryIs used to get a read/write file handle for the Channel

Note:Duplicatehandle () is needed to be able to access the channel after freeing hwtshandle (I. e. calling wtsvirtualchannelclose ()). the output handle from duplicatehandle () needs to be closed using closehandle ().

Bool bsucc = wtsvirtualchannelquery (

Hwtshandle,

Wtsvirtualfilehandle,

& Vcfilehandleptr,

& Len );

...

Handle hwtsfilehandle = * (handle *) vcfilehandleptr;

...

Bsucc = duplicatehandle (

Getcurrentprocess (),

Hwtsfilehandle,

Getcurrentprocess (),

& _ Hdvc,

0,

False,

Duplicate_same_access );

3) Overlapped readfile () and writefile () callare issued on the channel file handle

Bret = readfile (_ hdvc, readbuf, channel_pdu_length, & bytesread, & Ovr );

Bret = writefile (_ hdvc, ppacket, requiredlen, & byteswrit, & Ovr );

4) to close the connection the channel file handle is closed

Closehandle (_ hdvc );

Sample: ts-teleport

Ts-Teleport is a sample application to demonstrate the end to end use of the DVC APIs. it implements a simple protocol to transport files from the TS Server session to the desktop of the client machine. it does not rely on similar ts functionality like drive redirection.

The server component is a shell extension that adds an "RDP client desktop" entry to the "send to" context menu. upon indexing the list of highlighted files which the user elected to "send to the RDP client desktop", the shell extension opens the DVC and streams the files through. upon grouping the file names and data, the client component creates those files and directories on the desktop.

The server sends a series of state dependent requests to the client by writing on the DVC and for each request it reads the status through a DVC read. requests are start and end pairs for files and directories and data packets for file data.

Sample files and instructions

Please follow the link below to access sample files and instructions, including source code and installation how-.

Http://blogs.msdn.com/ts/pages/ts-teleport-sample-instructions.aspx

Author: Ahmed Tolba (SDE ts devices Team)

Credits: Eric Holk, zardosht kasheff, Josh Rosenberg and the rest of the TS devices team

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.