Run Batch File On Start-up

Batch FileWindows 7Startup

Batch File Problem Overview


Is there a way to start multiple programs in a batch file on system start-up? In addition to that, in that batch file, I would like to be able to say: Once I execute a program, wait until that program completely loads, and execute the next listed program.

Any help would be appreciated.

Batch File Solutions


Solution 1 - Batch File

I had the same issue in Win7 regarding running a script (.bat) at startup (When the computer boots vs when someone logs in) that would modify the network parameters using netsh. What ended up working for me was the following:

  1. Log in with an Administrator account

  2. Click on start and type “Task Scheduler” and hit return

  3. Click on “Task Scheduler Library”

  4. Click on “Create New Task” on the right hand side of the screen and set the parameters as follows:

    a. Set the user account to SYSTEM

    b. Choose "Run with highest privileges"

    c. Choose the OS for Windows7

  5. Click on “Triggers” tab and then click on “New…” Choose “At Startup” from the drop down menu, click Enabled and hit OK

  6. Click on the “Actions tab” and then click on “New…” If you are running a .bat file use cmd as the program the put /c .bat In the Add arguments field

  7. Click on “OK” then on “OK” on the create task panel and it will now be scheduled.

  8. Add the .bat script to the place specified in your task event.

  9. Enjoy.

Solution 2 - Batch File

To run a batch file at start up: start >> all programs >> right-click startup >> open >> right click batch file >> create shortcut >> drag shortcut to startup folder.

The path to the folder is : [D|C]:\Profiles\{User}\‌​AppData\Roaming\Micro‌​soft\Windows\Start Menu\Programs\Startu‌​p

Solution 3 - Batch File

Go to Run (WINDOWS + R) and Type shell:startup, paste your .bat file there !

Solution 4 - Batch File

To start the batch file at the start of your system, you can also use a registry key.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Here you can create a string. As name you can choose anything and the data is the full path to your file.

There is also the registry key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

to run something at only the next start of your system.

Solution 5 - Batch File

There are a few ways to run a batch file on start up. The one I usually use is through task scheduler. If you press the windows key then type task scheduler it will come up as an option (or find through administerative tools).

When you create a new task you can chose from trigger options such as 'At log on' for a specific user, on workstation unlock etc. Then in actions you select start a program and put the full path to your batch script (there is also an option to put any command line args required).

Here is a an example script to launch Stack Overflow in Firefox:

@echo off

title Auto launch Stack Overflow


start firefox http://stackoverflow.com/questions/tagged/python+or+sql+or+sqlite+or+plsql+or+oracle+or+windows-7+or+cmd+or+excel+or+access+or+vba+or+excel-vba+or+access-vba?sort=newest

REM Optional - I tend to log these sorts of events so that you can see what has happened afterwards
echo %date% %time%, %computername% >> %logs%\StackOverflowAuto.csv

exit

Solution 6 - Batch File

RunOnce

RunOnce is an option and have a few keys that can be used for pointing a command to start on startup (depending if it concerns a user or the whole system):

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

setting the value:

reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v MyBat /D "!C:\mybat.bat"

With setting and exclamation mark at the beginning and if the script exist with a value different than 0 the registry key wont be deleted and the script will be executed every time on startup

SCHTASKS

You can use SCHTASKS and a triggering event:

SCHTASKS /Create /SC ONEVENT /MO ONLOGON /TN ON_LOGON /tr "c:\some.bat" 

or

SCHTASKS /Create /SC ONEVENT /MO ONSTART/TN ON_START /tr "c:\some.bat"

Startup Folder

You also have two startup folders - one for the current user and one global. There you can copy your scripts (or shortcuts) in order to start a file on startup

::the global one
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
::for the current user
%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Solution 7 - Batch File

1. Copy the following lines to Notepad.

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Users\toto\your_file.bat" & Chr(34), 0
Set WshShell = Nothing

Note: Replace the batch file name/path accordingly in the script according to your requirement.

2. Save the file with .VBS extension, example launch_bat.vbs

3. Create new .bat file, in our case your_file.bat

4. Write the content of your .bat file. Example:

 @echo off
    php c:\laragon\www\my_app\artisan serve --host=127.0.0.1 --port=8000

5. Run your_file.bat and ejoy :)

Solution 8 - Batch File

If your Windows language is different from English, you can launch the Task Scheduler by

  1. Press Windows+X
  2. Select your language translation of "Computer Management"
  3. Follow the instruction in the answer provided by prankin

Solution 9 - Batch File

Another option would be to run the batch file as a service, and set the startup of the service to "Automatic" or "Automatic (Delayed Start)". Check this question for more information on how to do it, personally I like NSSM the most.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRandomishlyingView Question on Stackoverflow
Solution 1 - Batch FileprankinView Answer on Stackoverflow
Solution 2 - Batch FileTroubleshootView Answer on Stackoverflow
Solution 3 - Batch FileMilan MadubashaView Answer on Stackoverflow
Solution 4 - Batch FileRainer ZufallView Answer on Stackoverflow
Solution 5 - Batch FileChrisProsserView Answer on Stackoverflow
Solution 6 - Batch FilenpocmakaView Answer on Stackoverflow
Solution 7 - Batch FileGustave TsopmoView Answer on Stackoverflow
Solution 8 - Batch FilePeer SommerlundView Answer on Stackoverflow
Solution 9 - Batch FileGChufView Answer on Stackoverflow