locked
Clipboard Not Working from Remote Desktop Session RRS feed

  • Question

  • I have a WPF program that copies a bitmap to the clipboard from a click event.  The program is hosted on a terminal server that I access from my desktop via Remote Desktop.  I can paste the image into Paint and various other applications on the terminal server.  I can copy image from Paint on the terminal server to the clipboard on my PC and paste the image into Paint on my PC.  But when I copy the image from my program and try to paste it into applications on my PC, the clipboard is empty.  I've tried stopping and restarting rdpclip.  It doesn't help.  I've run a clipboard viewer program on my PC.  It responds to the Clipboard.Clear() command from my program running on the terminal server, but it does not respond to the Clipboard.SetImage() command.  I'm looking for any solution that allows me to copy the bitmap from the programming running on the terminal server and paste it directly into a program running on my PC.  It doesn't matter to me if I need to change my program code or change the settings that relate to the remote desktop session.  But if the solution needs to take place in the settings, please help me determine which settings to look at.

    My sample code is short and should be easy to follow.  Any help understanding the problem would be very much appreciated.

    MainWindow.xaml

    <Window x:Class="ClipboardTest.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="199" Width="240">
        <Grid Name="MainGrid" Background="Beige">
            <Button Content="Copy" Height="23" HorizontalAlignment="Left" Margin="70,65,0,0" Name="btnCopy" VerticalAlignment="Top" Width="75" Click="btnCopy_Click" />
        </Grid>
    </Window>

    MainWindow.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;

    namespace ClipboardTest
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }

            private void btnCopy_Click(object sender, RoutedEventArgs e)
            {
                FrameworkElement visual = MainGrid;

                RenderTargetBitmap wpf_bitmap = new RenderTargetBitmap(
                    (int)(visual.ActualWidth > 0 ? visual.ActualWidth : visual.Width),
                    (int)(visual.ActualHeight > 0 ? visual.ActualHeight : visual.Height),
                    96,
                    96,
                    PixelFormats.Pbgra32);
                wpf_bitmap.Render(visual);
                Clipboard.Clear();
                Clipboard.SetImage(wpf_bitmap);
            }
        }
    }

    Tuesday, April 17, 2012 6:02 PM

Answers

  • Hi,

    Did you try to connect a Windows 7 system remotely and use the app?  Since I have no Windows Server 2003 right now, I cannot test it. 

    Based on my research, if the clipboard chain does work between the two systems, we even cannot copy paste the images from the remote server to the local system by Ctrl + C and Ctrl + V.  The issue is very strange.  The clipboard works fine at the remote server, but only when you want to get the clipboard item which is set by your app at the local system, the clipboard does not work.  And you also mentioned that you have stopped and restarted the rdpclip, but it does not help.  So now I suspect the issue can be caused by your local network settings, but I am not sure.  

    I would recommend you post the question at this TechNet forum since there are more experts there, http://social.technet.microsoft.com/Forums/en-US/winserverTS/threads.  

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    Friday, April 20, 2012 2:03 AM

All replies

  • Hi Rich MMM,

    I am not sure if your issue is caused by WPF, I suggest you test your WPF part local, and check if copy/paste could work local, if it does not work without remoting, you could post your issue on WPF forum to get furthe support:

    http://social.msdn.microsoft.com/forums/en/wpf/threads

    best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 18, 2012 9:04 AM
  • Hi,

    Sheldon is correct.  We can narrow down the problem first.   Please first try to execute the app locally as Sheldon suggested.  If it can work fine at your local machine, then please try it remotely to see whether the image can be copied and pasted at the remote server, e.g. from the app to MSPaint at the remote server. 

    I believe if it is the remote desktop settings issue, your app will work fine in both above conditions. 

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, April 18, 2012 9:26 AM
  • I thought it would be clear when I said I could copy an image from my application running on the remote server and paste it into Paint on that same remote server, that I could also run my application on my PC and paste the image to my PC.  I guess that wasn't clear.  So yes, I can run my applicaiton on my PC, copy an image from my application, and paste the image to paint on my PC.  But I'm the developer of the application and have the freedom to install it on my PC.  The users of the application are required to run it from a remote desktop session.  And to repeat, images from other applications running on the terminal server can be copied to the clipboard running on the local PC so the settings related to the remote desktop session allow images to be copied at least some of the time.

    I hadn't tried running my app locally before and pasting the image to paint on the remote server.  But I tried that now and it worked correctly.

    Wednesday, April 18, 2012 3:05 PM
  • Hi,

    I did some test based on the sample codes you provided, however, I cannot repro the problem.   The image can be sent to the client machine without any problems.  I tested on two Windows 7 x64 systems.  Could you please let me know what Windows systems you are using now?  

    Besides, I would recommend you double check whether the Clipboard is shared with the remote server.

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Cor Ligthert Thursday, April 19, 2012 4:43 AM
    Thursday, April 19, 2012 1:57 AM
  • However, has nothing to do with C#. Is the same with windows explorer.

    Success
    Cor

    Thursday, April 19, 2012 4:44 AM
  • Thanks for the replies.

    The terminal server has Windows 2003.  I've tried clients with Windows7 64-bit and 32-bit.  All clients have the Clipboard button checked.  The code is compiled as a 32-bit application which is a requirement based on some of the dependencies in the full app which have not been included in the code I provided here.  The code uses the .Net 4 framework.

    Thursday, April 19, 2012 3:45 PM
  • Hi,

    I am not sure where the problem is since I use .NET 4.0 and build the app as x86 as well.  Maybe it's caused by some system issues of Windows Server 2003 or Windows XP since they have similar kernels.  Here is a related KB article, http://support.microsoft.com/kb/306885/en-us.  

    I would recommend you try to connect another system with Windows 7 and test the app again to further narrow down the issue.   Meanwhile, I suggest you check whether the Windows Server 2003 has installed all the lastest updates. 

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 19, 2012 4:33 PM
  • Even though I'm running Windows7, I tried the suggestion above for Windows Server 2003 and Windows XP.  I was able to find and check the Drives checkbox in my Remote Desktop Client settings.  It didn't help.

    But I think I may be experiencing two distinct problems and I believe only one of them is being addressed so far.  You have shown that my program as presented here can work, ie copy from the remote server and paste to the local PC, under some conditions.  Perhaps the conditions include a requirement that the server runs Windows Server 2008 or perhaps it is another group of settings on the local and remote computers.  The other issue is that even on the remote and local computers I'm actually using, with the settings as they actually are, copy-paste works with some applications including Paint running on the server.  So there must be something that makes my application different than Paint when it comes to copying from a Windows 2003 Server terminal server.  Any thoughts on that part of the problem?  Thanks again for the attention you are giving to this issue.

    Thursday, April 19, 2012 10:06 PM
  • Hi,

    Did you try to connect a Windows 7 system remotely and use the app?  Since I have no Windows Server 2003 right now, I cannot test it. 

    Based on my research, if the clipboard chain does work between the two systems, we even cannot copy paste the images from the remote server to the local system by Ctrl + C and Ctrl + V.  The issue is very strange.  The clipboard works fine at the remote server, but only when you want to get the clipboard item which is set by your app at the local system, the clipboard does not work.  And you also mentioned that you have stopped and restarted the rdpclip, but it does not help.  So now I suspect the issue can be caused by your local network settings, but I am not sure.  

    I would recommend you post the question at this TechNet forum since there are more experts there, http://social.technet.microsoft.com/Forums/en-US/winserverTS/threads.  

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    Friday, April 20, 2012 2:03 AM
  • You can run the following commands on your remote machine one by one.

    Taskkill.exe /im rdpclip.exe
    Rdpclip.exe

    This is a temporary fix, alternately you can use an online copy paste tool, its great.

    www.letscopypaste.com

    • Proposed as answer by raree Friday, October 5, 2012 2:59 PM
    Wednesday, July 18, 2012 10:02 AM