Is there a way to programatically copy and paste to an RDP?

3

2

I am looking to write a quick script to send one file (that I change often) from my workstation (windows7 OS) to a remote server (windows server 2012) via the RDP client.

Ideally, I am looking to instantiate the rdpclip.exe process with some arguments. Something like: rdpclip.exe -f [fileToCopyFromLocalToRemote] but to my knowledge (and a brief google search) there is no such equivalent.

Also, I am not looking for any third party tools to do this!

Matthew Peters

Posted 2015-09-02T16:38:54.590

Reputation: 1 718

Answers

1

You can use PowerShell to put file to clipboard:

Add-Type -AssemblyName System.Windows.Forms
$f = New-Object System.Collections.Specialized.StringCollection
$f.Add("D:\tmp\mypic1.bmp")
[System.Windows.Forms.Clipboard]::SetFileDropList($f)

Eldarien

Posted 2015-09-02T16:38:54.590

Reputation: 176

2To complete your answer, you need to add that the user needs to also add a script on the remote side to retrieve the copied file. Additionally, these two scripts would have to be in sync or at least responsive to each other. Furthermore, I'm not really sure if this will work and cannot test it myself (security issues on my local machine). If you could test it and address my first two points, this would be the simplest solution by far... – Matthew Peters – 2015-09-14T11:46:50.417

4

If you intend to stay connected to the RDP session, then you can map a drive on your connection which can make your local drive available to the remote computer. This is on Remote Desktop's Local Resources tab under the More... button.

Once that is enabled, you can make a scheduled task to copy files. You can access the local drives from the special share name \\tsclient\c or whichever drive you are trying to access, as described in this TechNet article. So a sample script that you would run on the remote computer might look something like this:

IF EXIST "\\tsclient\c\Mydir\MyFile" copy /Y "\\tsclient\c\Mydir\MyFile" "C:\Syncrhonized\MyDir\MyFile"

You could put this in as a scheduled task to run every few minutes or so. Be aware of a potential problem if other people remote in to this computer with drive mappings and file structure. Your script won't know which computer is the right one, unless you throw some sort of logic in to check that.

GuitarPicker

Posted 2015-09-02T16:38:54.590

Reputation: 1 137

I was just writing the similar but you beat me to it. The problem the user has is that you can't map a server drive locally via RDP and RDPClip.exe doesn't have any command line arguments so it can't be used programmatically. The ideal solution would be to VPN to the server and then any programmatic access can be done using native tools such as robocopy. To extend your answer you could recommend a VPN. – Kinnectus – 2015-09-09T13:28:03.060

I was trying to stay as close to the original request as possible, since I don't know the nature of the network. It could be that the server is on a firewalled DMZ network only available via RDP. My solution would be two parts - the RDP connection, and a script to run from the remote machine. Please note that \\tsclient is not a traditional server mapping, although it acts like one. It does not require network connectivity other than the RDP session through which it is tunneling. To clarify the answer a bit, tsclient is the literal name to use, not a placeholder. – GuitarPicker – 2015-09-09T13:36:10.097

So I cannot map a network drive because the security is locked down. Is there are way to use some native windows process (like rdpclip.exe) to just programmatically do what I can do manually with the clicking (copy and paste). Hypothetically, I see no reason this cannot be accomplished. The user is sending a command somewhere and the OS is interpreting that to actually perform the transfer.... – Matthew Peters – 2015-09-09T15:25:22.180

@Matthew: The solution I gave does not involve network drives. It uses the same syntax as a network drive, but it is not one. It all tunnels through the remote desktop session. You will have to manually or otherwise establish a remote desktop session to the computer with drive sharing enabled, but once that is complete, you can connect to \tsclient\c from the remote computer to get to the local computer's C drive. The link I included has screenshots of the whole process. Try it out. I use this technique frequently to move files to and from a remote machine that is on a secure network. – GuitarPicker – 2015-09-09T15:36:24.000

Old versions of RDP used to have a command line option to run an application when you connected, but I think this was removed a while back. Too bad, because it would really come in handy for what you are trying to do. – GuitarPicker – 2015-09-09T15:37:57.127

I may have called it the incorrect term but I cannot link my workstation's drives directly to the remote via the RDP client as described in the article you mentioned. – Matthew Peters – 2015-09-09T16:43:56.570

Ouch. It's possible that feature is being blocked by the server or through Group Policy. If that's the case, you may have to beg for an exception. Other convoluted ways of doing this are through some sort of Auto Hotkeys magic, but I'll let someone else write that answer. – GuitarPicker – 2015-09-09T17:01:01.573

This is exactly what I was looking for! Thanks – Friesgaard – 2018-02-21T07:42:07.860

1is there a way to copy from server without mapping the drive? can you provide some resources? – vaibhavcool20 – 2018-06-26T02:32:47.087

1

According to my research rdpclip.exe doesn't accept any command line arguments. To use it in order to programmatically copy files is apparently not intended.

Since Windows Vista robocopy is part of every Windows installation. I don't know how you wanna use rdpclip.exe to transfer a file to the remote host. But my first thought was to mount a netshare, use robocopy to transfer a file and dismount the netshare. In an script it will look like:

net use \\Server\Sharename /USER:[username] [passwort]
robocopy [Source] [Destination]
net use \\Servername\Sharename /del

hirnwunde

Posted 2015-09-02T16:38:54.590

Reputation: 11

Could you give an example? Let's say the server is 192.11.12.33 – Michael Haephrati – 2018-09-19T11:44:41.990

1

As you say that you cannot share your local hard disk with the server, the only sharing mechanism that is left is the clipboard.

If the clipboard is shareable over the RDP connection, you may use the open-source project Clipboard RDC.

This project consists of a very small Java program that is launched on both sides of the connection. The client-side program is used to encode a file and load it to the clipboard, while the server-side program decodes and stores it in a local file. The limitation here is that the file must be small enough to fit on the clipboard.

As it stands, this is more work than you wanted to do. But you can modify this simple program and separate it into two parts :

  1. A client-side program that will accept a file-path as parameter and place the encoded file on the clipboard.
  2. A server-side program that will loop, testing every few seconds for the presence of such a file on the clipboard, decoding and storing it in the folder.

As these will be your own programs that you fully control, you could add features such as adding the destination path to the information that you place on the clipboard, so that this becomes a general-purpose tool for automatically transferring multiple small-enough files from client to server.

harrymc

Posted 2015-09-02T16:38:54.590

Reputation: 306 093

Without digging too deep into clipboard RDC (which I will do anyway later), is there a native windows command to load something into the clipboard? If there is, I could essentially do just what the FOSS does but natively. – Matthew Peters – 2015-09-10T11:31:24.223

I mentioned that project as an example. If you are into Win32 API, then start with the SetClipboardData function. C/C++ will be easier than Java for interfacing with Windows.

– harrymc – 2015-09-10T12:09:56.760

You could also use the free utility nircmd.exe clipboard commands to load a file into and store from the clipboard.

– harrymc – 2015-09-12T09:36:08.730