How to copy a file to a remote computer's desktop when the remote computer could be Windows 7 or XP?

25,303

Just always use the XP version:

xcopy [path to local file] "\\%hostname%\c$\Documents and Settings\%user%\Desktop\"

It turns out that MS realized this would happen and put in a hidden junction from Documents and Settings to Users. You can't CD to it or DIR in it, but you can still use it for anything else you'd use Users for.

Share:
25,303
Kyle
Author by

Kyle

Updated on February 26, 2020

Comments

  • Kyle
    Kyle about 4 years

    I'm trying to create a script that copies a file to the desktop of a remote user. The two computers would be on the same network in the same domain.

    So far I've got a batch script that looks something like:

    @echo off
    set /p user="Username of remote user: "
    set /p hostname="Target computer name: "
    xcopy [path to local file] "\\%hostname%\c$\Users\%user%\Desktop\"
    

    The above script would only work for Windows 7. Is there a way to make it so that the script would somehow detect to see if the parent folder exists before copying, then if it does to copy? Or can this be achieved with environment variables?

    If I just let the above script run as is and the target computer is using Windows XP, then a new directory tree will be created, which is what I'd like to avoid.

    https://support.microsoft.com/kb/65994 would work if I were checking the local system, but I'm trying to see if the remote computer's destination folder exists. I don't see how this article answers that.

  • Harry Johnston
    Harry Johnston about 9 years
    Note, however, that this won't work if the system administrator has relocated the desktop folder. That's not a problem for code used in-house, which is presumably is the OPs scenario, but commercial products would need to be more careful.