Avatar of Magnus_Bleken
Magnus_Bleken
 asked on

Programmatically save files om Remote Desktop copied on local machine into clipboard?

How can I programmatically save files to server-disk when Connected to Remote Desktop when the files are on local machine copied into the clipboard?

I don't mean "open Explorer and hit CTRL+V" or use \\tsclient\c....
When doing this locally I use OpenClipBoard, GetClipboardData and DragQueryFile... but this doesn't work when using it on Win10/2008R2 Remote desktop "server" when files are copied on local disk onto clipboard..

Any suggestions?
Last resort is finding a way to open Windows Explorer in a new directory and hitting CTRL+V/using API to paste it.. I'll take suggestions here too :)
Visual Basic ClassicFoxProMicrosoft Server OSWindows Server 2008Microsoft Applications

Avatar of undefined
Last Comment
Magnus_Bleken

8/22/2022 - Mon
jrbbldr

As long as within your Remote Desktop connection - on the Local Resources tab and within the More option you have the Check on the C:   (meaning Share Drives) you can save any file to the local workstation using the "tsclient" as the pseudo-UNC.

For example:  
 \\tsclient\C\Temp 

Open in new window

    points to the local workstation's C drive and its TEMP subdirectory.

WIth that in mind your VFP application can do something like:  
COPY FILE FileOnRDPWorkstation.xxx TO "\\tsclient\C\Temp\FileOnLocalWorkstation.xxx" 

Open in new window



Good Luck
Magnus_Bleken

ASKER
Thanks for Your reply, jrbbldr but that is not what I need.
I cannot use normal file copy (\\tsclient or another UNC). Nor can I use FTP or any other conventional file copy like robocopy/xcopy.
The user is connected to his local computer and puts files in the clipboard (selecting them and hitting CTRL+C).
Then he goes over to his Remote Desktop and that is where I need them.. programmatically.
If the user opens a folder and hits CTRL+V then the files are pastes there.. But I need to do this in code so it Works seemlessly in my Application :)
jrbbldr

OK, here is what I have found....

When you do a COPY of one or more filenames from a Windows Directory, the files themselves are not copied to the Clipboard (maybe you already knew that).

I just did a trial and found that after doing that, the contents of the Clipboard was a list of the fully pathed filenames that were 'Copied'  (NOTE:  I used the FreeClipboardViewer 3.0 tool   -   http://www.freeclipboardviewer.com/  )
For example:
C:\Temp\Oakley File-1.dat
C:\Temp\Oakley File-2.dat

Open in new window


So your VFP code would need to Read the Clipboard contents and acquire the list of files.
( I have yet to find that answer, but I will continue looking and perhaps someone else will have that part of the puzzle. )

Then, using that list, do as I have suggested above with the:
COPY FILE FileOnRDPWorkstation.xxx TO "\\tsclient\C\Temp\FileOnLocalWorkstation.xxx" 

Open in new window


Good Luck
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Pavel Celba

So it seems you need to programatically control the RDS session... Similar as if somebody else could control your regular Windows session... Do you think it is secure?

jrbbldr showed one way which requires to access shared folder on the remote computer.

Of course, you can do it opposite way - make your local drives visible in RDS session and then you may simply copy whatever you need by running program on the remote computer. More info: https://www.raymond.cc/blog/transfering-files-from-local-computer-to-connected-remote-desktop-session/
Magnus_Bleken

ASKER
Thanks both of you.
jrbbldr: this could work fine when files is copied from local or mapped volume, mot when copied from UNC.. But I will try this :)

pcelba: I don't want to Control the RDS session, I only want to open an Explorer-Window and hit CTRL+V With .visible=FALSE in the background.. programmatically... When user is running their app using RemoteApp then they won't be able to start other programs like Explorer to browse your local disks :)

This is a very specific routine I want to make :)
jrbbldr

One question...

I assume that the user on the Remote Desktop will be doing the File Copy to Clipboard directly in Windows and outside of any VFP application.

How will your VFP application 'know' when this is done and thereby will attempt to copy the files to the local workstation?

Good Luck
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jrbbldr

Well I have found the following:

Retrieve List of Files from Clipboard
https://www.berezniker.com/content/pages/visual-foxpro/retrieve-list-files-clipboard

I have not tried it, so Good Luck with it.
But the question I asked above still stands - How will the VFP application 'know' when there is a list of files to Copy/Move?

If the user has to do some action to 'tell' the VFP application to initiate the Copy/Move, then why allow them to do it 'outside' of the application at all.  
They would be better to select the list of files within the application and the whole job would be easier.

Good Luck
Pavel Celba

To open an Explorer-Window and hit CTRL+V in RDS session from local computer is nothing else than RDS session control. Any program having System privileges can do it. If you know how to propagate physical key press into RDS session window then you have the solution. It will just need elevated rights. Everything must be done at much lower level than OpenClipBoard, GetClipboardData and DragQueryFile etc.  But I would do it different way.

RDS session can see your local discs or folders (and printers) when you connect so copy your files to some local folder which is visible for RDS and another program running in RDS can do the rest.
Magnus_Bleken

ASKER
I've requested that this question be deleted for the following reason:

Made a workaround and nobody obviously understood my question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Pavel Celba

You were asking for "Any suggestions"... I would like to know what is the "workaround" in such case?
Rob-Down-Under

Perhaps post your workaround ?
That will Have two benefits -
- We might better understand your question
- Others who have trouble transferring files from/to RDS (eg me), might be interested in the solution
ASKER CERTIFIED SOLUTION
Magnus_Bleken

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pavel Celba

I don't see how could the code paste the file from local computer into RDS session folder but the question discussion is not the  candidate for deletion.

Please select ID: 41494961 as the answer.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Magnus_Bleken

ASKER
The last codegroup pastes as verb and works fine
Pavel Celba

Yes, you just have to execute the code in RDS not on local machine which is OK in fact.
jrbbldr

But you still have not said how the code 'knows' when it needs to be run.

If the user on the RDS has to manually launch the code after having copied the filenames to the clipboard, you might as well have had the user do the whole thing within the application thereby making the whole task much easier - most likely eliminating the use of the clipboard entirely.

Good Luck
Your help has saved me hundreds of hours of internet surfing.
fblack61
Magnus_Bleken

ASKER
My intentions with this was to have a button in a CRM-module called "Paste files from clipboard" with a shourtcut ALT+V - then I could also map CTRL+V to this button. This is running on a RDS/terminal server using RemoteAPP (the user then only sees the application not the rest of the desktop on the server.
The user browses their local computer and selected som files/folders.. Copies them onto the clipboard and switches back to the application running on the terminal server.

So my workaround is as follows, and the only thing I could find to do it for now. (I can not use \\tsclient as the files might be on a local UNC path, I can not use http/ftp or other protocols to retrieve the files as they are only available through the clipboard).

Invoke Scripting.FileSystemObject to delete temp-folder with files and sub-folders:
    lcMappe = gcTemp + 'MAB_TempPaste'
    IF DIRECTORY((lcMappe), 1)
      loFSO = CREATEOBJECT("Scripting.FileSystemObject")
      loFSO.GetFolder(lcMappe).DELETE(.T.)
      RELEASE loFSO
    ENDIF

    IF !DIRECTORY((lcMappe), 1)
      MKDIR (lcMappe)
    ENDIF

Open in new window


Invoke Shell.Application to walk through the possible verbs on the folder and DO/RUN when "PASTE" ("Lim inn" in Norwegian) is found. I had to walk through them like this instead of using .DoVerb('PASTE') as this would not always work even with & in the right place.
    loShell = CREATEOBJECT("Shell.Application")
    loNS = loShell.NameSpace(lcMappe)
    FOR lnCount = 1 TO loNS.SELF.Verbs.COUNT
      WITH loNS.SELF.Verbs.ITEM(lnCount)
        lcVerb = ALLTRIM(UPPER(.NAME))
        lcVerb = CHRTRAN(lcVerb, '&', '')
        IF INLIST(lcVerb, 'PASTE', 'LIM INN')
          .Doit()
        ENDIF
      ENDWITH
    ENDFOR

Open in new window


This does work and are therefor a solution/workaround for my question.
Pavel Celba

More sophisticated solution would be to make local disks/folders visible in RDS and allow the direct file selection in the remote app.

BTW, this workaround does not mean "programmatically save files to server-disk" because files are saved on local disk :-).
Magnus_Bleken

ASKER
No that is not correct because a local UNC will never be available to the RDS unless it is mapped.
That is _one_ of the reasons why I need to use the clipboard.
And no.. files are saved on server-disk when you hit CTRL+V/PASTE when you are connected to RemoteAPP or RDS - try it

Just to point this out one more time. The Application is running on the RDS/terminal server.. It is NOT ran on local computer.. It's running using RemoteAPP so the user only sees the Application - not the servers full desktop. So CTRL+V will paste files to "the application's chosen folder" which is on the server.

BTW! We also have the possibility for the user to browse local folders (\\tsclient) of course.. But when you use a computer, keyboard shortcuts will always be faster
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Pavel Celba

Yes, I understand it.

I have just been pointing to the wording. "Server" means server from the local workstation point of view.  If some program runs on the server like your RemoteAPP then it uses local disks (C:, D:, E:, ...).  They are on the server but RemoteAPP is also running on the server so it does not access these disks as server disks over the network (most probably) but these disks are local disks for the RemoteAPP. Local disks on the client workstation would have been "redirected" not "mapped" disks for RemoteAPP if you would allow it in your RDS session settings.
Magnus_Bleken

ASKER
Ok, to clarify - define:
Local computer (let's call it "PC")
Terminal server/RDS (let's call it "TS")

The user is using PC and puts some files into the clipboard (could be files from PC's C: or PC's UNC-available path.
The user then switches over to a RemoteAPP running on TS and wants to paste the files onto this app - could be like to attach the files to a customer or something.
TS then needs to be able to paste PC's files onto TS's available disks.
What I do with this workaround is to create a local temp-path on TS and then TS pastes the files there (from the clipboard redirected using RDS). RDS then copies the files from local clipboard/paths onto TS's temp-folder which I specified.
My Application (running as RemoteAPP on TS) then scans through this temp-folder and adds all files, scans through sub-folders and add files there etc etc.
Then the temp-folder (on TS) is deleted (from the RemoteAPP). The files are not deleted on PC as I only use verb 'PASTE' from RemoteAPP (running on TS) with TS' folders.

I do not I can make myself any clearer
Rob-Down-Under

This is not exactly what you want, but there are a lot of people who would be over the moon if they knew this -

File Transfer using RDP
http://geekswithblogs.net/DesigningCode/archive/2010/04/19/file-transfer-using-rdp.aspx

I just tested it and it is great.
Perhaps you could programmatically (on the server) pull files that are in a local folder ?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Magnus_Bleken

ASKER
Rob-Down-Under: thank you. I'm aware of this and we use this when the user hits a button called "Browse" in our system.. But we would also like to be able to paste what's in the clipboard. I always uses clipboard or drag'n'drop myself.. :)
jrbbldr

My intentions with this was to have a button in a CRM-module called "Paste files from clipboard" with a shourtcut ALT+V - then I could also map CTRL+V to this button.

OK, that makes what you are trying to do more clear.

BUT why involve the Clipboard at all?

Why not have the CRM module open its own Explorer window and allow the user to select the files right there.
Then the CRM application itself would 'know' which files where selected and where they were located.
With that 'knowledge' IT could Copy/Move the files itself and not involve the Clipboard in any way.

Good Luck
Magnus_Bleken

ASKER
jrbblr: because, as I have stated multiple times, we already have a browser-button already. But when you run the application ("MAB") from a RDS/terminalserver (RemoteAPP) you don't have access to your local computer's (PC) UNC (other computers/servers in PC's network).
If you try to browse, from RemoteAPP, to your local computer (which is on LAN while RemoteAPP is in another network/country/whatever), you only have Access to your local drives/mapped drives (if you have redirected the drives at all).
So if you have files in \\localfileserver\share\directory .. then you will not be able to BROWSE to them from RemoteAPP..
So you select them in PC's Explorer and click CTRL+C to put them in your clipboard.. RemoteAPP then pastes them in a temp-folder in RemoteAPP's local temp (which is the server-disk) and imports the files from there.

There are not many other solutions, and again: I can not use RDP drive redirection as this do not redirect UNC - and if you have the file on your desktop it would be easier to put it in clipboard instead of navigating to \\tsclient, c, user, username, desktop and then selecting the file.. Nor can I use FTP, http or any other protocol because the user don't necessary have this.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Pavel Celba

@Magnus_Bleken: You've created good work around for the conditions given and your post ID: 41494961 should be selected as the solution. This question should not be deleted.
Magnus_Bleken

ASKER
Workaround