run python script from startup code example
Example 1: how to run python file in when windows startup
C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Content of run_script.cmd
python path\to\your\script.py
Example 2: python execute on startup windows
import getpass
USER_NAME = getpass.getuser()
def add_to_startup(file_path=""):
if file_path == "":
file_path = os.path.dirname(os.path.realpath(__file__))
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'start "" %s' % file_path)