Walkthrough: Share an Application Process with Another User (Lync 2010 SDK)

This topic shows how to share an application process in a conversation by using .NET Framework managed code with Microsoft Lync 2010 SDK.

To create the desktop sharing application

  1. Sign in to Microsoft Lync 2010.

  2. In Microsoft Visual Studio development system, create a new Microsoft Windows Forms application.

  3. Select .NET Framework 3.5 or 4.0 as the target framework. For more information, see How to: Target a Specific .NET Framework Version or Profile.

  4. Add a reference to Microsoft.Lync.Model.

  5. In Form1.cs, add the following using statement.

    using Microsoft.Lync.Model;
    using Microsoft.Lync.Model.Extensibility;
    
  6. In the Form1_Load event handler, add the following code that implements the following tasks:

    1. Declares and instantiates a conversation context data dictionary.

    2. Gets an Automation instance that is called to start the conversation.

    3. Sets the modes of the conversation to application sharing and instant messaging.

    4. Gets the processes that run on the local computer and choose the first running process.

    5. Sets instant messaging and application sharing resource context for the conversation and then begin the conversation.

    
    // a) Create a dictionary object to contain AutomationModalitySettings data pairs. 
    Dictionary<AutomationModalitySettings, object> _ModalitySettings = new Dictionary<AutomationModalitySettings, object>();
    
    // b) Get the Automation object.
    Automation _Automation = LyncClient.GetAutomation();
    
    // c) Specify the conversation modes of application sharing and instant messaging.
    private AutomationModalities _ChosenMode = AutomationModalities.ApplicationSharing | AutomationModalities.InstantMessage;
    
    // d) Declare and instantiate an array of Process instances to hold all processes running on local computer.
    
    Process[] RunningProcesses = System.Diagnostics.Process.GetProcesses();
    Process runningProcess = RunningProcesses[0];
    
    // Get the selected Process Id and convert to int.
    uint selectedProcess = Convert.ToUInt32(runningProcess.Id);
    
    // Get the main window handle of the selected process and convert to int.
    uint selectedWindowHandle = Convert.ToUInt32(runningProcess.MainWindowHandle);
    
    // Add the process Id to the modality settings for the conversation.
    _ModalitySettings.Add(AutomationModalitySettings.SharedProcess, selectedProcess);
    
    // Add the main window handle to the modality settings for the conversation.
    _ModalitySettings.Add(AutomationModalitySettings.SharedWindow, selectedWindowHandle);
    
    // Adds text to toast and local user IMWindow text-entry control.
    _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "Hello Elise. I would like to share my first running process with you.");
    _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);
    
    
    // Declare the string array.
    string[] invitees = {″elise@contoso.com"};
    
    IAsyncResult ar =  _Automation.BeginStartConversation(
                        _ChosenMode
                        , invitees
                        , _ModalitySettings
                        , null
                        , null);
    
    // Block UI thread until conversation is started.
    _Automation.EndStartConversation(ar);
    
    
    
    
  7. Build and run the application. After the invited user accepts the process sharing request, the local computer’s running instance of the first process appears within the remote Microsoft Lync 2010 conversation window.

For more information about sharing programs, see Errors and troubleshooting.

Show: