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.
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.