Virtual Channels – More awesome than you think

Hey there, Recently I came across some really interesting thing called “Virtual Channels”. I had no idea what they are. As it turns out they are some pretty nice though, difficult feature given by Microsoft to do stuff when you do Remote Desktop C…

Hey there,

Recently I came across some really interesting thing called “Virtual Channels”. I had no idea what they are. As it turns out they are some pretty nice though, difficult feature given by Microsoft to do stuff when you do Remote Desktop Connection to some other computer. Once you figure out how does it work, it can be a pretty neat implementation.

Ever wonder what happens when you do Ctrl+C in one computer and Ctrl+V in another computer while you are in Remote Desktop Connection how does it just works? How it basically copies data from one user space in one computer and pastes into another? Obviously there is some sort of connection. Enter Virtual Channels.

According to msdn: “Virtual channels are software extensions that can be used to add functional enhancements to a Remote Desktop Services application. Examples of functional enhancements might include: support for special types of hardware, audio, or other additions to the core functionality provided by the Remote Desktop Services Remote Desktop Protocol (RDP). The RDP protocol provides multiplexed management of multiple virtual channels.

This is very interesting to me. It means I can make my desktop app host it on one server(probably Terminal Server) and let the client computer RDP into my host/server computer and access the app/software from there. Since each user has its own user space and separate Virtual Channel there wont be any problems when multiple clients would connect to my server via Remote Desktop Connection.

If you are wondering what is this? Or want to learn about Virtual Channels here are some links that were helpful to me while understanding Virtual Channels.

http://blogs.msdn.com/b/rds/archive/2007/09/20/dynamic-virtual-channels.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/aa383546(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/dd644622(v=prot.10).aspx

Lets take an example, Let’s assume there is a software hosted on such a computer and everyone RDP’s into it. Now let’s say this software is supposed to print receipts, obviously the receipt printer has be on the client computer, what are the ideas of implementing this?

Sure you can have a web service, tcp connection etc. but that requires opening ports into your clients firewall, which may or may not be acceptable. One of the option is Virtual Channel or Dynamic Virtual Channel, msdn provides great explanation on what are those.

There is one particularly great example about Virtual Channel. Here is the link

http://blogs.msdn.com/b/rds/archive/2007/09/19/ts-teleport-sample-instructions.aspx

This is very old yet beautiful example. The code attached in the above URL is for older visual studio and older Terminal Server. While I started from this I updated the code to work for Visual studio 2010 and Windows Server 2008 R2. It does not work if you convert your project into Visual Studio 2010 project. I have gone through the pain so you don’t have to :)

Apparently Posterous does not allow me to upload zip files. That is the reason i posted alternative for uploading zip files in posterous blog before this one.

However you can access the folder form this link

This is a great starting point for anyone coding for Terminal Server using Dynamic Virtual Channels.

Here are couple of things that I discovered and could be helpful.

  • The client plug-in has to be of the same bitness(x86/x64) of the mstsc.exe on the client (RDP executable)
  • It helps if it’s Unicode
  • The above URL mentions the use of support dll while doing regsvr32, since you are using new Visual studio you will need updated support dlls, you can find them at

C:Program Files (x86)Microsoft Visual Studio 10.0VCredistDebug_NonRedistx86Microsoft.VC100.DebugCRT (of course it is x86/x64, debug/release according to your configuration)

Other details are dependent on what you want to do with Virtual Channels.

I hope this is helpful to you. In case you have any questions let me know.

Keep coding, later!