Run python script as a windows service

Is there a way to run my python 3 script when booting the system on Windows 7?

I know this was 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 switch to ActivePython.

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

Thank you in advance,

mafrasi2

+6
source share
3 answers

Assuming you have a completely isolated exe woking file created from your python script using py2exe , you can simply add a new line with some random key and value as the absolute path your EXE file under HKLM\Software\Microsoft\Windows\CurrentVersion\Run from the windows registry (available when starting regedit from the Window run prompt). This will run the exe file every time you boot Windows 7!

+1
source

You can use the sc command. I can’t check it right now, but I think it will look like this: sc create MyCoolService start = auto binpath = c: \ mycoolprogram \ supercool.exe obj = LocalSystem displayname = CoolService

See link for command syntax

+1
source

You can also use the Windows task scheduler by following these steps (skip quotation marks when typing):

  • Search for "Task Scheduler" in the start button search box
  • Create new task
  • In the Create Task dialog box, go to the Triggers tab and click the Create button
  • Select "On Startup" from the "Start Task" drop-down menu, click "OK"
  • Go to the "Actions" tab and click "Create"
  • The "Action" drop-down should display "Start Program"
  • In the "Program / script" field, enter "python.exe"
  • In the "Add arguments" field, enter the full path to your python script with any arguments, such as "C: \ Scripts \ startupscript.py -c onstart"
+1
source

Source: https://habr.com/ru/post/954656/


All Articles