Python WMI – Get list of services on machine

In this post we will be creating a Python script that will get a list of services on the local machine. To do this we will be using the ‘WMI’ module, short for Windows Management Instrumentation. This module allows access to most information about a computer system.

To install the WMI module run the following command.

pip install WMI

See the sample of Python code where we utilize the WMI module to get a list of all services on the local machine. We start by connecting to the windows system and then query the list of services. The name of the service along with its state is returned to output.

import wmi

c = wmi.WMI()

services = c.Win32_Service()

for service in services:
    print(f"Service: {service.Name} (Status: {service.State})")

A snippet of output for the script can be seen below.

Service: BITS (Status: Stopped)
Service: Bonjour Service (Status: Running)
Service: BrokerInfrastructure (Status: Running)
>>> 

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply