Sep 28

How can I restart Windows service with Python?

First you need to install excellent Python for Windows extensions (pywin32) by Mark Hammond from http://sourceforge.net/projects/pywin32/.

Then you can use the following code (that will restart the Print Spooler service).

import win32serviceutil

serviceName = "spooler"


Note: this code was tested with Python 2.7 and version 216 of the pywin32 extensions.