4

I am trying to write a batch file that will copy itself to the startup folder in Windows 7 for all users.

I have tried this code here:

copy test.bat "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" 

and it does notwork. However, if I input this code instead:

copy test.bat "C:\Users\Kreature\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" 

it works but the problem is that I need this to be universal for all accounts.

Laf
  • 7,965
  • 4
  • 37
  • 52
user222586
  • 41
  • 1
  • 1
  • 3

6 Answers6

1

I guess that you must call the script from an admin account in order to copy a file to the system folders. Try "Execute as administrator" on CMD and call your script.

user3407000
  • 188
  • 2
  • 10
  • i think your right because i tried in cmd and it said access denied also running the file as admin did nothing, 0 file copyied. idk what to do – user222586 Mar 19 '14 at 20:14
  • http://stackoverflow.com/questions/11525056/how-to-create-a-batch-file-to-run-cmd-as-administrator You could try this. – user3407000 Mar 19 '14 at 20:18
0

Probably, you don't have permissions to write to folders shared by all users, so the first part fails. But you can write to your own folders, so that part works.

Søren Debois
  • 5,598
  • 26
  • 48
  • hmmm okay, umm is there a way to give permission mayby add a line of code to force admin... but i ran as admin and nothing – user222586 Mar 19 '14 at 20:17
  • Could you maybe say what the error message you get is? – Søren Debois Mar 19 '14 at 20:18
  • C:\Users\Kreature\Desktop>copy test.bat "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" Access is denied. 0 file(s) copied. – user222586 Mar 19 '14 at 20:19
  • in cmd it just says Access is denied. 0 file(s) copied – user222586 Mar 19 '14 at 20:23
  • ok so drag and drop works with the file but asks for admin permision but yet running the bat file as admin does nothing – user222586 Mar 19 '14 at 20:26
  • 1
    ok i got it figured out in a way. i compiled the .bat file to a .exe file with admin manifest using a bat to exe converter and it copyied over, would still be nice to find a way to do it without clicking yes for admin permision – user222586 Mar 19 '14 at 20:32
0

You can just do this: copy test.bat "C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" %USERNAME% will be automatically filled in with the user's username.

  • This doesn't really answer the question - which clearly states that expected outcome is to copy file to startup folder for *all* users. – bardzusny Aug 09 '15 at 08:17
0

Was looking for a solution and couldn't find any so i dived in batch basic and realized it's pretty simple. Hoping you have the file you need copied to every user startup and you have admin privs on the system. create a batch file as below:

@echo off
set back=%cd%
for /d %%i in ("C:\Users\"*) do (
cd "%%i"
REM copy "C:\Users\Administrator\Desktop\file.cmd" "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
echo.
echo -----------------------------------------------------------------------------------------------
dir "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
echo -----------------------------------------------------------------------------------------------
echo.
cd ..
timeout 2 > NUL
)
cd %back%
Ombre
  • 21
  • 4
0

Try using :

copy %0 "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup" 

%0 stand for local file with path. U can change the %0 to any file you want.

%appdata% will redirect you to this path : C:\Users\[user]\AppData\Roaming

0

I made this script that copies any files to startup. I made it in Windows 10 so I don't know if it will work.

try this instead:

copy "example.bat" "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"

It also works with .txt, .bat, .vbs, ... files.

If you want you can try it on older versions of Windows, it should work..

Aultr
  • 1
  • 3
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 21 '22 at 14:06