-
#17
Заколебался каждый раз, когда отваливается пул или меняется монета, прописывать новый батник в автозагрузку. Решил немного автоматизировать процесс: при запуске батник сам создает ярлык на себя в автозагрузке. Ярлык всегда называется START.lnk, поэтому каждый раз просто пересоздается на последний запущенный батник.
Программу для создания ярлыков брал здесь http://optimumx.com/downloads.html , называется Shortcut, поместил в папку Windows для доступности (без необходимости добавлять лишний путь в PATH). Программа старая, 2005 года, но под win10 работает.
И вначале каждого батника дописал:
shortcut.exe /a:c /f:»%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\START.lnk» /t:»%~f0″
cd /D «%~dp0»
Тестировал все на Windows 10.
PS дописал смену рабочей директории в случае, если путь до майнера относительный.
Последнее редактирование:
The easiest way to run a batch file on a system startup is to place it in the Windows “Startup” folder or drop there a shortcut.
Programs placed in this folder are meant to run automatically whenever the computer boots up.
In this note i will show how to run a batch file on a system startup for the “Current User” and for “All Users”.
Cool Tip: Create a batch file to run an .exe
program! Read more →
Press the ⊞ Win + R keyboard shortcut to launch the “Run” dialog.
To open the “Startup” folder for the “Current User”, type:
shell:startup
To open the “Startup” folder for the “All Users”, type:
shell:common startup
Click “OK” and paste your batch file or the shortcut to the .bat
file, that needs to be run on a Windows startup.
Cool Tip: Get the return code from the last command or application! Read more →
Was it useful? Share this post with the world!
Чтобы поставить .bat
файл в автозагрузку в Windows, выполните следующие шаги:
-
Откройте папку автозагрузки:
- Нажмите
Win + R
, чтобы открыть окно «Выполнить». - Введите
shell:startup
и нажмитеEnter
. Это откроет папку автозагрузки для текущего пользователя.- Если вы хотите, чтобы скрипт запускался для всех пользователей, введите
shell:common startup
.
- Если вы хотите, чтобы скрипт запускался для всех пользователей, введите
- Нажмите
-
Добавьте ваш
.bat
файл в папку автозагрузки:- Скопируйте ваш
.bat
файл. - Вставьте его в открытую папку автозагрузки.
- Скопируйте ваш
-
Проверьте, что файл добавлен:
- Убедитесь, что ваш
.bat
файл находится в папке автозагрузки.
- Убедитесь, что ваш
-
Перезагрузите компьютер:
- После перезагрузки ваш
.bat
файл должен автоматически запуститься.
- После перезагрузки ваш
Дополнительный метод с использованием Планировщика заданий:
Если ваш .bat
файл требует прав администратора или вы хотите более гибкие настройки запуска, вы можете использовать Планировщик заданий:
-
Откройте Планировщик заданий:
- Нажмите
Win
и введите «Планировщик заданий», затем откройте приложение.
- Нажмите
-
Создайте новую задачу:
- В разделе «Действия» выберите «Создать задачу».
-
Настройте задачу:
- Вкладка «Общие»:
- Укажите имя задачи.
- Отметьте «Выполнять с наивысшими правами», если нужны права администратора.
- Вкладка «Триггеры»:
- Нажмите «Создать» и выберите «При входе в систему».
- Вкладка «Действия»:
- Нажмите «Создать» и выберите «Запуск программы».
- В поле «Программа или сценарий» укажите полный путь к вашему
.bat
файлу.
- Вкладка «Общие»:
-
Сохраните задачу:
- Нажмите «ОК» для сохранения настроек.
-
Проверьте работу задачи:
- Перезагрузите компьютер и убедитесь, что
.bat
файл запускается автоматически.
- Перезагрузите компьютер и убедитесь, что
Примечание: Будьте осторожны с файлами в автозагрузке, так как они будут запускаться каждый раз при старте системы, что может влиять на время загрузки Windows.
Download Windows Speedup Tool to fix errors and make PC run faster
Occasionally, you might need to schedule to run a batch file automatically in your Windows. In this article, I’ll share a tip on how to schedule a Batch file automatically using Task Scheduler.
To schedule a Batch File to run automatically in Windows 11 and Windows 10, you will have to follow these steps:
- Create a Batch file
- Open Task Scheduler
- Create a Basic Task
- Open Task Scheduler Library
- Make Task runs with the highest privileges.
Step 1: Create a batch file you wish to run and place it under a folder where you have enough permissions, for example, under C drive.
Step 2: Click on Start and under search, type in Task, and click open Task Scheduler.
Step 3: Select Create Basic Task from the Action pane on the right of the window.
Step 4: Under Create Basic Task, type in the name you like and click Next.
Step 5: From the Trigger, select the option you like and click Next.
I chose Daily and clicked Next, which brought me to this screen.
Step 6: Then click on Start a Program and click Next.
Step 7: Now click on Browser and select the batch file you would like to run.
Step 8: Finally, click on Finish to create the Task.
Now that we have created a Task, we must ensure it runs with the highest privilege. Since we have UAC settings, we have to make sure that it should not fail if it does not bypass the UAC settings when you run the file.
So click on Task Scheduler Library.
Then, double-click on the Task you just created.
Step 8: Click on Run with Highest privilege, then click OK.
Congratulations!
You have successfully created a Scheduled Task to automate a batch file. However, there can be drawbacks such as if the application you are trying to invoke needs a password. In that case, you cannot run it silently.
How do I run multiple batch files after one?
If you want to run batch files one after another, you can use the task scheduler and time them to run with the one-minute gap. The other way is to create a mother batch file, add a list of all bat files inside it, and let it execute one after the other.
How to add timeout or sleep in a Batch File?
You can add the following command along with other parameters. It will ensure user input is not considered, and there is no output for this.
timeout /t 30 /nobreak > NUL
How to run the batch files on Startup?
When setting up the task with the scheduler, you can run it as soon as you log into the PC. It can be delayed by a minute, but it will be executed. If you need to run it every few minutes, make sure to set it accordingly.
Shyam aka “Captain Jack” is a Microsoft MVP alumnus and a Windows Enthusiast with an interest in Advanced Windows troubleshooting. Suggestions made and opinions expressed by him here are his personal ones and not of his current employers.