Copying files as administrator in a batch file
You must have local admin rights to write to that folder and your batch file will need to be ran with elevated permissions (Run As Adminstrator).
user2997716
Updated on July 28, 2020Comments
-
user2997716 almost 4 years
So I have a batch file that copies files from one folder to a bunch of different folders.
The purpose of this batch file is to be like a simple installer(Without registry edits) to make it easier for others to use a set of files I am distributing. Because this is being widely distributed, it will need to work on windows operatings systems from XP on. The files need to be moved to the program files of a program (This works), their documents folder(Also works), and the program folder in the all users start menu(Does not work).
So far I have been unsuccessful with xcopy and robocopy as they both tell me "access denied". Also running the batch file with "Run as administrator". If you can think of a more effective way to do what I'm trying to do besides a batch file I am open to ideas.
xcopy /q /y ".\add_ui.bat" "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\My Program\Add.bat"
I'm sure there's some simple trick that I'm missing.
Thanks in advance!
-
user2997716 over 10 yearsIs there anyway for me to get around that?
-
jonsinfinity over 10 yearsNo, there is no way around it. Do you have to put the files in the All Users Start Menu? Could you instead put them in the current user's Start Menu?
-
user2997716 over 10 yearsUnfortunately not, it's sort of an add on to an existing program which uses the all users start menu. It's for low technical ability uses so I would end up confusing them with the current users start menu. I'm not totally attached to .bat files, do you suggest anything that might be easier? Thanks so much for your responses so far!
-
Harry Johnston over 10 yearsIf "Run as administrator" succeeds, then you have local admin rights.
-
jonsinfinity over 10 years@HarryJohnston You're correct. My original answer wasn't clear on that.