Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a python script as a windows service

Tags:

python

windows

Is there a way to run my python 3 script at system boot on windows 7?

I know this has been asked a couple of times, but none of the solutions really filled my needs, because I prefer to stay with the free python interpreter rather than switching to ActivePython.

I have installed the Python for Windows extensions and would use py2exe, but it does not support Python 3.

like image 855
mafrasi2 Avatar asked Sep 26 '13 07:09

mafrasi2


2 Answers

You can also use the Windows Task Scheduler using the following steps (skip quotes when typing):

  • Search 'Task Scheduler' in Start button search box
  • Create a new task
  • In 'Create Task' dialog, go to 'Triggers' tab and click 'New' button
  • Select 'At startup' from the 'Begin the task' dropdown, click 'OK'
  • Go to 'Actions' tab and click 'New' button
  • 'Action' dropdown should show 'Start a program'
  • In 'Program/script' box, type 'python.exe'
  • In 'Add arguments' box, type the full path to your python script with any arguments, such as 'C:\Scripts\startupscript.py -c onstart'
like image 165
jsucsy Avatar answered Nov 04 '22 23:11

jsucsy


Assuming that you have a fully woking stand alone exe file that's been generated from your python script using py2exe, you can just add a new string with some random key and value as the absolute path of your exe file under HKLM\Software\Microsoft\Windows\CurrentVersion\Run of windows registry (accessible by running regedit from Window's run prompt). This will run the exe file whenever your Windows 7 boots up !

like image 42
Shan Valleru Avatar answered Nov 04 '22 21:11

Shan Valleru