从远程桌面中运行的应用程序中,如何以编程方式获取已复制到客户端剪贴板的文件并将其保存到磁盘

发布于 2024-11-05 08:43:57 字数 655 浏览 4 评论 0原文

场景如下:

  1. 用户在运行 Windows 2008 Server R2 的服务器上打开远程桌面会话。
  2. 远程桌面会话不使用映射驱动器,但启用了剪贴板共享。
  3. 用户在远程桌面会话中启动 MyApplication。
  4. 用户在客户端计算机上打开 Windows 资源管理器并将文件复制到剪贴板。
  5. 在 MyApplication(在远程桌面会话中)中,用户单击“保存文件”按钮。
  6. MyApplication 从剪贴板获取文件并将其保存到服务器上的某个目录。

MyApplication 是一个旧的 vb6 应用程序,但可以在 .Net 中实现它并通过 com interop 使用它。我们尝试了 vb6 中的 Clipboard 类和 .Net 中的 Systems.Windows.Forms.Clipboard 类。 在任何一种情况下,剪贴板上唯一的内容似乎是客户端计算机上的文件路径。这是没有用的,因为代码是在服务器上运行的,我们需要从服务器获取文件。

我们还确认,当我们手动将文件粘贴到服务器上的 Windows 资源管理器(通过远程桌面)时,这确实有效。 我们确实找到了一些示例,展示了如何通过在客户端上运行另一个程序来实现此目的,但这对我们来说不是一个选择。这必须仅在远程桌面上工作。 任何帮助、代码示例、文档链接等将不胜感激。

This is the scenario:

  1. User opens a remote desktop session on a server running Windows 2008 Server R2.
  2. The remote desktop session does not use mapped drives but clipboard sharing is enabled.
  3. User launches MyApplication in the remote desktop session.
  4. User opens Windows Explorer on client machine and copies a file to the clipboard.
  5. In MyApplication (in the remote desktop session) user clicks a "Save File" button.
  6. MyApplication gets the file from the clipboard and saves it to some directory on the server.

MyApplication is an old vb6 application, but it is okay to implement this in .Net and use it through com interop. We have tried both the Clipboard class in vb6 and the Systems.Windows.Forms.Clipboard class in .Net.
In either case the only thing that seems to be on the clipboard is the file path on the client machine. This is of no use since the code is running on the server and we need to get the file from the server.

We have also confirmed that this does work when we manually paste the file into Windows Explorer on the server (through remote desktop).
We did find some examples that show how to do this by running another program on the client, but that is not an option for us. This has to work over just remote desktop.
Any help, code samples, links to documentation etc. would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦冥 2024-11-12 08:43:57

那么通过远程桌面连接的驱动器共享是否启用? (当您转到“选项”、“本地资源”并单击“更多”时,“驱动器”选项未选中)

如果是这样,则无法通过远程桌面连接将文件复制并粘贴到 Windows Exporer 窗口,而且我不知道如何解决它会 - 文件剪贴板/拖放操作本质上是通过将文件路径放置在剪贴板上,然后允许目标应用程序对文件执行他们希望的操作(通常复制文件或打开它)。通过远程桌面使用驱动器共享时,可以通过 //tsclient“共享”使用文件,但是除非在远程连接上启用此功能,否则目标应用程序(包括 Windows 资源管理器)将无法访问文件。

如果启用了驱动器共享,那么您应该会发现文件的路径(可通过 //tsclient 共享访问)被放置在剪贴板中 - 您应该能够以以下方式访问此路径下的文件:与任何其他共享上的文件类似。

您可能还会发现剪贴板查看器(例如这个)很有用。

So drive sharing over the remote desktop connection is not enabled? (When you go to Options, Local Resources and click More the "Drives" option is unticked)

If so then copying and pasting a file over a remote desktop connection to a Windows Exporer window doesn't work, and I can't see how it would - file clipboard / drag and drop operations essentially work by placing the file path on the clipboard, and then allowing the destination application do what they wish with the file (normally copy the file or open it). When using drive sharing over remote desktop the files are available through the //tsclient "share", however unless this is enabled on the remote connection the destination application (including Windows Explorer) will have no way of accessing the file.

If drive sharing is enabled then you should find that the path to the file (as accessible through the //tsclient share) is placed in the clipboard - you should be able to access files under this path in a similar way to files on any other share.

You may also find a clipboard viewer (like this one) useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文