How to create a python script that runs automatically at startup (WINDOWS)

in Programming & Dev2 years ago (edited)

So people love automation because it simplifies their lives. Sometimes hosting a script in a proper platform is too much of a hassle / overkill for a simple script. I wondered if there was a way to run a script at windows startup. If all that malware can do it (example recently installed antivirus that installs you 5 more apps from them that start lagging your pc as soon as you turn it on) then I can probably do the same for a simple py script:

First we create a simple script and paste it into a blank .py or .pyw file:

import time 

while True:
    try:
        print("3")
    except:
         print("an error ocurred")
    time.sleep(10)

Then we need to create a .bat file and paste there:

"C:\Python310\python.exe" "C:\Users\fefe\Desktop\Nueva carpeta\test.py"

That's how it looks for me first goes python's path and then paste our script file's path

Let's test it! Everything seems to work fine

image.png

Now we need to make it work at startup:

Press WindowsKey + R
Write shell:startup and press enter again to get startup folder
Then drag/copy your .bat file there

All done!

A few fair warnings:

  1. you need to log in in your pc session for it to start working.
  2. having a script running while you're doing other stuff is quite a bother, there are a many sites that explain how to run them while minimized or on the background: https://www.winhelponline.com/blog/run-bat-files-invisibly-without-displaying-command-prompt/

I have been thinking about a script that would claim hive-engine rewards automatically, so this is probably a good way to get that working.

Sort:  

Very nice! And it's actually kinda easy. I know a bit about python and with your detailed explanation, I'm pretty sure I can replicate this. About making a script that can claim hive rewards automatically, I think someone else beat you to that 😆 hive.vote does exactly that

Thanks!
Oh, so that's why my post rewards are claimed automatically? I had forgotten all about that. I don't think it works for hive-engine rewards though

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

Congratulations @fefe99! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You received more than 700 upvotes.
Your next target is to reach 800 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Our Hive Power Delegations to the August PUM Winners
Feedback from the September 1st Hive Power Up Day
Hive Power Up Month Challenge 2022-08 - Winners List
Support the HiveBuzz project. Vote for our proposal!

Glad, I saved this.