Python WMI – Get system users

In this post we will be creating a Python script that will get the list of system users 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 the list of system users on the machine. We start by connecting to the windows system and then query the user accounts.

import wmi

c = wmi.WMI()

users = c.Win32_UserAccount()

for user in users:
    print(f"User: {user.Name} (Type: {user.AccountType})")

An example of what the above would return can be seen below.

User: Admin (Type: 512)

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

Leave a Reply