Run a Python program at start-up on Windows

10,804

Solution 1

I don't use Windows, but you can try making a batch script that runs your python file and make that script Run a program automatically when Windows starts:

  1. Click the Start button Picture of the Start button , click All Programs, right-click the Startup folder, and then click Open.

  2. Open the location that contains the item you want to create a shortcut to.

  3. Right-click the item, and then click Create Shortcut. The new shortcut appears in the same location as the original item.

  4. Drag the shortcut into the Startup folder.

As I said, I don't use Windows, so it might be totally wrong.

You can refer here for making the BAT file, which basically says:

@echo off
python c:\somescript.py %*
pause

Solution 2

Use VBScript:

1-> create anyname.vbs with this data:

Set wvbs=CreateObject("Wscript.Shell") wvbs.run "full location of your File",0

2-> copy anyname.vbs file in C:\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup this folder

Now when windows start it will run your file in hidden mode

Solution 3

I think that the above answers are too complex. What I did was just drag and drop or copy and paste my file in the startup folder by clicking the quick access toolbar, typing "startup", and the job is done.

screenshot of file manager

I am using Windows 10 operating system, so it might be different in your case.

I hope this is useful.

Edit: The key to this solution is to have the .py extension files open by default by the python console (not a text editor), otherwise it will just open the file instead of executing it. In order to select the default program a type of file is opened with, right click on the .py file -> Open with -> Choose default program. See this example:
screenshot of open with prompt

Share:
10,804
Richard Paul Astley
Author by

Richard Paul Astley

Updated on June 04, 2022

Comments

  • Richard Paul Astley
    Richard Paul Astley almost 2 years

    I am developing a key-logger on Python (only for curiosity sake). And the script will be an executable. Without access to the computer so the process should not need a UI or user interaction.

    Is there any way, even in another executable to make the key-logger start at start-up ?