I am trying to create a small program that copies a file to another system. the name of the system is previously selected (is a variable = "testsystem"). I have this Sub and Function:
Sub tst
Dim copythis
copythis = "xcopy.exe /Y c:\temp\version.bat " & testsystem & "\temp"
Set objShell = CreateObject("Wscript.Shell")
Msgbox AddQuotes(copythis)
objShell.Run AddQuotes(copythis)
End Sub
Function AddQuotes(strInput)
AddQuotes = Chr(34) & strInput & Chr(34)
End Function
The messageBox displays exactly the string that I need: the full command. Also, if I execute the command manually it works:
C:\temp>xcopy /Y c:\temp\version.bat \\testsystem3\temp
C:\temp\version.bat
1 File(s) copied
I have been battling with this for 2 days now. I guess I am missing some quotes somewhere but can't figure it out.
Thank you!