This question has already been answered:

There is a program written in python, which lines of code you need to add, so that it always runs and works when you start the OS Windos

Marked as a duplicate by D-side members, Vladimir Martyanov , jfs python Jan 30 '18 at 10:30 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    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) 

    Add this code to your source. This code creates a .bat file in which your script runs. The .bat file itself is located in the Startup folder, which contains autorun applications at system startup.