Copying files as administrator in a batch file

25,457

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).

Share:
25,457
user2997716
Author by

user2997716

Updated on July 28, 2020

Comments

  • user2997716
    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
    user2997716 over 10 years
    Is there anyway for me to get around that?
  • jonsinfinity
    jonsinfinity over 10 years
    No, 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
    user2997716 over 10 years
    Unfortunately 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
    Harry Johnston over 10 years
    If "Run as administrator" succeeds, then you have local admin rights.
  • jonsinfinity
    jonsinfinity over 10 years
    @HarryJohnston You're correct. My original answer wasn't clear on that.