Search code examples
vbscriptremote-accessfilesystemobjectfile-copying

VBScript FileSystemObject.CopyFile() to remote computer Path Not Found


Here's a simple script that I can't get to work the way I want it to:

Const Overwrite = True
remoteHost = "DESKTOP1"
sDestination = "\\" & remoteHost & "\C:\Users\betsy\Desktop\"
sSource = ".transferFile.txt"

Wscript.Sleep 2000

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile sSource ,sDestination, Overwrite

msgbox "The file sent: " & sDestination & "."

This gives me Path not found. Very confusing. Why wouldn't it give me a Permissions Denied instead? When I actually sit at Betsy's computer, the path is exactly C:\Users\betsy\Desktop\. This path absolutely does exist on the remote computer - I've checked it 100 times. Maybe my sDestination string is not formatted correctly?

It works when I change sDestination to this...

sDestination = "\\" & remoteHost & "\Desktop1-Share\"

... but it's not in the correct place.

P.S. \\DESKTOP1\Desktop1-Share\ is a shared folder configured on the remote computer but I need to send the file to my cow Betsy's desktop folder \\DESKTOP1\c:\Users\betsy\Desktop, hopefully without configuring shared-folders.

The whole point of this script is to copy a file to 1 or more remote computers without having to physically sit at them. I have literally hundreds of computers to do this to but only need to prove to myself it can be done to at least one remote computer.


Solution

  • Have you tried

    sDestination = "\\" & remoteHost & "\Users\betsy\Desktop\"