1

I would like a python script as a Windows service, using sc. The problem is that the path to the executable has a space and requires parameters.

Therefore

sc create DNSResolver127 binPath= '"C:\Program Files (x86)\Python36-32\python.exe" D:/32dsdnsproxy/32dsdnsproxy.py'

fails (I tried to enclose the whole option in single quotes)

How to add such a service?

1

You have to escape the quote marks like this:

sc create MyService binpath= "\"C:\Program Files (x86)\Python36-32\python.exe\" D:/32dsdnsproxy/32dsdnsproxy.py"

... but keep in mind that this will only work if 32dsdnsproxy.py is designed to run as a service, otherwise you'll need to use a tool such as nssm or Apache Daemon's procrun to launch your application as a service.

  • Thank you. Is there something special to handle when starting a script as a service?(sorry, I am from the Unix world) – WoJ Jul 12 at 9:10
  • nssm is a godsend. I installed the script without any problems. Thank you! – WoJ Jul 12 at 9:22
  • Windows services have to interact with the operating system, at a minimum they need to report that they have successfully started. I've never tried this myself, but I believe that you can write a windows service in Python, e.g., see here - I expect that nssm will meet your immediate needs, but knowing that this is possible might come in handy later. :-) – Harry Johnston Jul 12 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.