简体   繁体   中英

Cant find files when copying in batch in administrator mode

I am writing a batch file to setup a small program that I have written for a couple of user's machines. As the batch file will be also writing to the user's registry it will be run in admin mode. The issue I have is when running in administrator mode when it gets to the COPY (I have also tested with the MOVE command) it outputs that the system cannot find the file. However if i run the program without the admin privileges the files copy/move as expected. I have tested the file without the registry command as well as that seems to have no effect on the situation. The initial files are all located in a folder on the users desktop but I have hard-coded the path names in to ensure that there is no confusion. I do have admin rights onto the machine as do all users for their respective computers. The contents of the batch file is listed below:

REM This program needs to be run as administrator for it to add to the registry
REM Adds a registry value that allows the user to right click a document and run the program

@echo off

MD %UserProfile%\AppData\Roaming\Microsoft\AddIns\ComparisonAddin

COPY C:\Users\MyUser\Desktop\Launch Files\Compare.xlsm %UserProfile%\AppData\Roaming\Microsoft\AddIns\ComparisonAddin
COPY C:\Users\MyUser\Desktop\Launch Files\launchCompare.bat %UserProfile%\AppData\Roaming\Microsoft\AddIns\ComparisonAddin

REG ADD "HKCR\*\shell\Get Word Difference\command" /v "" /t REG_EXPAND_SZ /d "\"%USERPROFILE%\AppData\Roaming\Microsoft\AddIns\ComparisonAddin\launchCompare.bat\" \"%%1\""

pause

The directory is created as normal in both admin mode and non admin mode. Is there any reason why the COPY/MOVE command does not work in admin mode?

Thanks.

COPY "C:\Users\MyUser\Desktop\Launch Files\Compare.xlsm" "%UserProfile%\AppData\Roaming\Microsoft\AddIns\ComparisonAddin\"

Any source or target that contains separator characters like space, comma, tab etc. must be "quoted".

I use the trailing backslash at the end of directory name as a matter of habit so that if the directory does not exist, the copy won't try to create a destination file with that name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM