Did you ever need to log on your clients PC and assist them? There are tons of desktop sharing applications around, some commercial and some are free, however if you knew how easy it is, to build a desktop sharing application working on Vista, you would never
give a
chance to other solutions.
Windows Vista comes with a brand-new desktop sharing software named Meeting Space which replaces the old Netmeeting. In our sample we will build our own Client (Viewer) and Server (Hoster) applications using Windows Desktop Sharing API (RdpEncom.dll). The Windows Meeting Space and Remote Assistance are using the same API.
There are two main components to use;
RDPSRAPISharingSession – COM object to share current desktop.
IRDPSRAPIViewer – ActiveX Viewer
Host Application
Let’s start with our Server (Host) application. Below is the form design of my server application. The three buttons are Button1, Button2 and Button3 in the same order. I will use the textbox to show the invitation connectionstring later on.

Before switching to the code view we need to add the RDPComapi DLL reference to our project.

Now we can start with our VB code. First of all import the RDPCOMAPILib to the form and define a global RDPSession.
Imports
RDPCOMAPILib
Public
Class
Form1
Dim
x
As
New
RDPSession
End
Class
In order to specify the clients rights when they connect, we will need an event handler for our sessions OnAttendeeConnected event.
Private
Sub
Incoming(ByVal
Guest
As
Object)
Dim
MyGuest
As
IRDPSRAPIAttendee
= Guest
MyGuest.ControlLevel
=
CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE
End
Sub
In the code above, current incoming user will be passed as a parameter to the event. We assign it to our own variable and set the ControlLevel to CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE. There are many ControlLevel choices. You can choose the one that fits to your solution. Now is the time to attach our event handler and run the host.
Private
Sub
Button1_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
AddHandler
x.OnAttendeeConnected,
AddressOf
Incoming
x.Open()
End
Sub
Client and Host connection in Windows Desktop Sharing API is build through connectionstrings. The host will create a connectionstring and you will need to pass it to the client with an e-mail, msn etc. Now we will create an invitation ticket in order to use it with our client application.
Private
Sub
Button2_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
Dim
Invitation
As
IRDPSRAPIInvitation
=
x.Invitations.CreateInvitation("Trial",
"MyGroup",
"",
10)
TextBox1.Text
=
Invitation.ConnectionString
End
Sub
After the creation of a ticket I just show the connectionstring in a TextBox. You can copy and paste it to the client application. It would be a better solution to save the connectionstring into an independent invitation file.
Finally, here is the total solution with the shut down code as well.
Imports
RDPCOMAPILib
Public
Class
Form1
Dim
x
As
New
RDPSession
Private
Sub
Button1_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
AddHandler
x.OnAttendeeConnected,
AddressOf
Incoming
x.Open()
End
Sub
Private
Sub
Incoming(ByVal
Guest
As
Object)
Dim
MyGuest
As
IRDPSRAPIAttendee
= Guest
MyGuest.ControlLevel
=
CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE
End
Sub
Private
Sub
Button2_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
Dim
Invitation
As
IRDPSRAPIInvitation
=
x.Invitations.CreateInvitation("Trial",
"MyGroup",
"",
10)
TextBox1.Text
=
Invitation.ConnectionString
End
Sub
Private
Sub
Button3_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button3.Click
x.Close()
x =
Nothing
End
Sub
End
Class
Client Application
In our client application we will use the IRDPSRAPIViewer ActiveX object. You will need to add it to your toolbox.

Now you can just drag’n’drop an RDPViewer to your form. I arranged some TableLayoutPanels so my RDPViewer will resize when the form gets resized.

Private
Sub
Button1_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
Dim
Invitation
=
InputBox("Insert
Invitation
ConnectionString",
"Attention")
AxRDPViewer1.Connect(Invitation,
"User1",
"")
End
Sub
Simply we get the connection string with an inputbox from the user and transfer it to our Viewer. In our host we didn’t specifiy any password, so we leave it blank here
too. The complete client application code is below.
Public
Class
Form1
Private
Sub
Button1_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
Dim
Invitation
=
InputBox("Insert
Invitation
ConnectionString",
"Attention")
AxRDPViewer1.Connect(Invitation,
"User1",
"")
End
Sub
Private
Sub
Button2_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
AxRDPViewer1.Disconnect()
End
Sub
End
Class
Conclusion
It’s really very easy to build desktop sharing application with Vista. All the user interaction etc. is totally handled by the API. You can integrate this system into any windows client project on which you are working. When your customers need assistance about any software you prepared, they just build an invitation from your applications “help” menu and send you. No need to struggle any other program.
You can download the sample source code below.
Desktop Sharing (Host and Client) - 10072007_1.rar (280.89 KB)