# How to run python script on windows startup?

**URL:** <https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800>\
**Category:** Python Help\
**Created:** [April 12, 2024, 2:18pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800 "2024-04-12T14:18:05Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey5588](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sergey5588/32/19170_2.png) [@Sergey5588](https://discuss.python.org/u/Sergey5588)\
**Post date:** [April 12, 2024, 2:18pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/1 "2024-04-12T14:18:05Z")

</div>

.bat file with python E:\pycode\Automation.py does nothing but when i run this command manually it works fine, any ideas?

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [April 12, 2024, 2:48pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/2 "2024-04-12T14:48:30Z")

</div>

Try using this in the .bat:

```python
call py E:\pycode\Automation.py

```

Does that work?

If not you will need to share all of the .bat file for review - its outside of python, but enough people here will be able to review.

---

<div class="post-metadata">

**Author:** ![Sergey5588](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sergey5588/32/19170_2.png) [@Sergey5588](https://discuss.python.org/u/Sergey5588)\
**Post date:** [April 12, 2024, 3:01pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/3 "2024-04-12T15:01:41Z")

</div>

It did not help, my batch file - startup.bat, located in shell:startup contains only  
`call py E:\pycode\Automation.py`

---

<div class="post-metadata">

**Author:** ![FelixLeg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/felixleg/32/18439_2.png) [@FelixLeg](https://discuss.python.org/u/FelixLeg)\
**Post date:** [April 12, 2024, 3:07pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/4 "2024-04-12T15:07:32Z")

</div>

Are you sure your .bat file (not python) is run at all? What you have done to make it running at Windows startup? (I mean things like: specific location on disk or the Windows Registry)

---

<div class="post-metadata">

**Author:** ![Sergey5588](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sergey5588/32/19170_2.png) [@Sergey5588](https://discuss.python.org/u/Sergey5588)\
**Post date:** [April 12, 2024, 3:09pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/5 "2024-04-12T15:09:34Z")

</div>

the console opens with the executed command and after time closes

---

<div class="post-metadata">

**Author:** ![FelixLeg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/felixleg/32/18439_2.png) [@FelixLeg](https://discuss.python.org/u/FelixLeg)\
**Post date:** [April 12, 2024, 3:12pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/6 "2024-04-12T15:12:32Z")

</div>

I suspect there may be some errors, but the terminal closes too fast to see them.  
Try add `pause` at the end of your .bat file.

---

<div class="post-metadata">

**Author:** ![Sergey5588](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sergey5588/32/19170_2.png) [@Sergey5588](https://discuss.python.org/u/Sergey5588)\
**Post date:** [April 12, 2024, 3:14pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/7 "2024-04-12T15:14:55Z")

</div>

nothing, just empty line, could this be due to the fact that I’m using pyAutoGui?

---

<div class="post-metadata">

**Author:** ![FelixLeg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/felixleg/32/18439_2.png) [@FelixLeg](https://discuss.python.org/u/FelixLeg)\
**Post date:** [April 12, 2024, 3:21pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/8 "2024-04-12T15:21:15Z")

</div>

Possibly. I know next to nothing about pyAutoGui except that it is used to moving mouse and typing.  
I think that your script is being run at so early moment at the startup that there is nothing yet on the screen that your script was trying to do.

Could you explain briefly what you script was supposing to do?

---

<div class="post-metadata">

**Author:** ![Sergey5588](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sergey5588/32/19170_2.png) [@Sergey5588](https://discuss.python.org/u/Sergey5588)\
**Post date:** [April 12, 2024, 3:23pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/9 "2024-04-12T15:23:15Z")

</div>

run Win + r  
type cmd and enter  
and type java command to start minecraft server and some other things

---

<div class="post-metadata">

**Author:** ![FelixLeg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/felixleg/32/18439_2.png) [@FelixLeg](https://discuss.python.org/u/FelixLeg)\
**Post date:** [April 12, 2024, 3:25pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/10 "2024-04-12T15:25:20Z")

</div>

Um…I think you don’t need pyAutoGui at all. Try to run the command for java from the Python itself 😉

---

<div class="post-metadata">

**Author:** ![Sergey5588](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sergey5588/32/19170_2.png) [@Sergey5588](https://discuss.python.org/u/Sergey5588)\
**Post date:** [April 12, 2024, 3:29pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/11 "2024-04-12T15:29:46Z")

</div>

it cause error, AccessDeniedException i think same with py auto gui

---

<div class="post-metadata">

**Author:** ![FelixLeg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/felixleg/32/18439_2.png) [@FelixLeg](https://discuss.python.org/u/FelixLeg)\
**Post date:** [April 12, 2024, 3:39pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/12 "2024-04-12T15:39:05Z")

</div>

After a bit of thinking I concluded you may not need Python at all 😉  
If you find a way to run a program in .bat file, then nothing stops you from putting there a command to run the server itself.

---

<div class="post-metadata">

**Author:** ![Sergey5588](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sergey5588/32/19170_2.png) [@Sergey5588](https://discuss.python.org/u/Sergey5588)\
**Post date:** [April 12, 2024, 3:42pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/13 "2024-04-12T15:42:52Z")

</div>

solution was very simple, just make task in task scheduler and make it with highest permission

---

<div class="post-metadata">

**Author:** ![FelixLeg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/felixleg/32/18439_2.png) [@FelixLeg](https://discuss.python.org/u/FelixLeg)\
**Post date:** [April 12, 2024, 3:52pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/14 "2024-04-12T15:52:17Z")

</div>

You can do that from script too. Just write:

```txt
start /REALTIME java -jar minecraft_server.jar [the rest of parameters]

```

I hope admins won’t get angry at me for a bit of off-topic 😜

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [April 12, 2024, 6:19pm UTC](https://discuss.python.org/t/how-to-run-python-script-on-windows-startup/50800/15 "2024-04-12T18:19:10Z")

</div>

> [@Sergey5588](#):
>
> and type java command to start minecraft server and some other things

Have you looked into other ways to autostart Minecraft?
