Python Win32serviceutil Install Service

Service

  • The functions this recipe uses from the win32serviceutil module are StartService, StopService, RestartService, and QueryServiceStatus. Each takes two arguments: the name of the service and the name of the machine. The first three perform the start, stop, and restart as requested. The fourth returns a structured code describing whether and how.
  • As is common with Python extensions, there are two Python modules that can work with services: The win32service module implements the Win32 service functions, while the win32serviceutil module provides some handy utilities that utilize the raw API.
Install

You can check Windows system service status using Python.Using psutil import win32serviceutil win32serviceutil.QueryServiceStatus('ServiceName')(272, 4, 7, 0, 0, 0, 0) # 4 means it's running win32serviceutil.QueryServiceStatus('ServiceName')(272, 1, 0, 0, 0, 0, 0) # 1 means it's stoppedUsing wmiYou can lookup with conditions like StartMode and State.

Latest version

Released:

Windows Service Manager Module that wraps for the win32service api

Project description

The author of this package has not provided a project description

Python

Release historyRelease notifications | RSS feed

1.1.1

Python Win32serviceutil Install Service

1.1.0

1.0.5

1.0.4

1.0.3

1.0.2

1.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pywinservicemanager, version 1.1.1
Filename, sizeFile typePython versionUpload dateHashes
Filename, size pywinservicemanager-1.1.1.tar.gz (28.2 kB) File type Source Python version None Upload dateHashes
Close

Hashes for pywinservicemanager-1.1.1.tar.gz

Hashes for pywinservicemanager-1.1.1.tar.gz
AlgorithmHash digest
SHA256f952af24aacde83a78fc6422e4a6d582778c298bd1c67d08c822fd9035a960ed
MD5b797cd3dadbe987fdf62f7ff95123f15
BLAKE2-256ff24a2662f27d05adc3b7b0eae313a6ef8d2c88bcc5ccf1758b32a0bdb235051

There are several ways to create and install a Python application as a Service in Windows. Learn More about Windows service using Python here.

Headless processes (with no UI) in Windows are called Services. They can be controlled (started, stopped, etc) using standard Windows controls such as the command console, PowerShell or the Services tab in Task Manager. A good example might be an application that provides network services, such as a web application, or maybe a backup application that performs various background archival tasks.

Windows service using Python: A Python script that can be run as a service

The modules used in this example are part of pywin32 (Python for Windows extensions). Depending on how you installed Python, you might need to install this separately.

This is just boilerplate. Your application code, probably invoking a separate script, would go in the main() function.

You will also need to install this as a service. The best solution for this at the moment appears to be to use Non-sucking Service Manager. This allows you to install a service and provides a GUI for configuring the command line the service executes. For Python you can do this, which creates the service in one go:

Where my_script.py is the boilerplate script above, modified to invoke your application script or code in the main() function. Note that the service doesn’t run the Python script directly, it runs the Python interpreter and passes it the

main script on the command line.

Python Win32serviceutil Install Service

Alternatively you can use tools provided in the Windows Server Resource Kit for your operating system version so create the service.

Running a Flask web application as a service

Install Win32serviceutil

This is a variation on the generic example. You just need to import your app script and invoke it’s run() method in the service’s main() function. In this case we’re also using the multiprocessing module due to an issue accessing WSGIRequestHandler.

Python Win32serviceutil

Adapted from https://stackoverflow.com/a/25130524/318488