Python Win32serviceutil Install Service

You can check Windows system service status using Python.

Using psutil

Here are the examples of the python api win32serviceutil.InstallService taken from open source projects. By voting up you can indicate which examples are most useful and appropriate. How do I install a service?-'Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams' Sorry I didn't reply sooner. If you're creating a service based on a Python file, check out the following links in addition to the book. Contrary to the name, it works with both Windows 2000 and Windows XP as well. Here are some instructions for how to install a python script as a service. Installing a Python script Run ServiceInstaller to create a new service. (In this example, it is assumed that python is installed at c: python25) Service Name: PythonTest Display Name. 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.

Python Win32serviceutil Install Service Pack

>>> import win32serviceutil
>>> win32serviceutil.QueryServiceStatus(“Service_Name”)
(272, 4, 7, 0, 0, 0, 0) # 4 means it’s running
>>> win32serviceutil.QueryServiceStatus(“Service_Name”)
(272, 1, 0, 0, 0, 0, 0) # 1 means it’s stopped

Using wmi

Python Win32serviceutil Install

Service

You can lookup with conditions like StartMode and State. Following code enumerates services whose StartMode is “Disabled” and current State is “Stopped”.

>>> import wmi
>>> c=wmi.WMI()
>>> c.Win32_Service(StartMode=”Disabled”, State=”Stopped”)
[, , , , , , , , ]

Check if specific service is running or not. Empty array is returned if the service is not running.

Python Win32serviceutil Install Service Pack


>>> c.Win32_Service(Name=”Netlogon”, State=”Running”)
[]