I'm trying to copy a file system.exe to a folder using xcopy in a .bat file. Here is the code. The system.exe file is in same directory as the .bat file.
md "C:\Users\Public\sys\"
set copy="%~dp0system.exe"
set target="C:\Users\Public\sys\"
xcopy /c copy target /i /r /f
I also tried this.
xcopy /c "copy" "target" /i /r /f
And this.
xcopy /c "%~dp0system.exe" "C:\Users\Public\sys\" /i /r /f
All gave the same response
File not found
The first two tries gives
File not found - copy
If the above lines succeed, the following lines in the .bat will create a shortcut to the copy of system.exe at the startup folder.
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%programdata%\Microsoft\Windows\Start Menu\Programs\Startup\startup.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "C:\Users\Public\sys\system.exe" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
That's what I hoped to achieve. Any help appreciated.
add:
I ran the .bat as administrator
You have to use this %copy%
and %target%
EDIT: @aschipfl got it first. Sorry not to look at your comment first.