I want my python file to run if Windows is booted up every single time, so I used this simple code:
Background.py (This creates a .bat
file which will run my desired .py
file on every windows startup)
import getpass
import os
USER_NAME = getpass.getuser()
def add_to_startup():
bat_path = r'C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup' % USER_NAME
with open(bat_path + '\\' + "open.bat", "w+") as bat_file:
bat_file.write(r'C:\Users\intel\AppData\Local\Programs\Python\Python38\python.exe C:\Users\intel\Desktop\Python programs\testing.py %*')
add_to_startup()
And this is the .py
file which I want to run every time:
with open(r"C:\Users\intel\Desktop\hello.txt", "w+") as test_file:
test_file.write(r'start')
But it's not working even if my computer is on :(
Edit 1:
I checked The startup folder also and the open.bat
file is successfully created and existing...
(You can even check in the image)
enter code here