Registry / devops / wmi
library1.5.1pypypi✓ verified 24d ago

The Python WMI module is a lightweight wrapper on top of the `pywin32` extensions, providing a more Python-friendly interface to Microsoft's Windows Management Instrumentation (WMI) API. It allows Python to query and manage various aspects of Windows systems, both locally and remotely, by abstracting the complexities of COM and WMI scripting. The latest version is 1.5.1, released in April 2020. The library is in maintenance mode with infrequent updates, as newer alternatives like `PyMI` and `windows-tools.wmi_queries` exist.

pip install wmi
INSTALL
IMPORT
SIG · WMI
W
wmi
devopspythonv1.5.1
Install
2.4s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WMI
import wmi c = wmi.WMI()
The primary class for connecting to the WMI service and performing queries.

This quickstart demonstrates how to connect to the local WMI service, retrieve basic operating system information, list a few running processes, and find automatically starting services that are currently stopped. It includes a placeholder for remote connections, emphasizing the use of environment variables for credentials for security best practice, and basic error handling for common WMI issues.

import wmi import os # Connect to the local machine WMI service # For remote connection, set WMI_USERNAME and WMI_PASSWORD environment variables: # c = wmi.WMI(computer="remote_machine_ip", user=os.environ.get('WMI_USERNAME', ''), password=os.environ.get('WMI_PASSWORD', '')) try: c = wmi.WMI() # Get information about the operating system for os_info in c.Win32_OperatingSystem(): print(f"OS Name: {os_info.Caption}") print(f"Version: {os_info.Version}") print(f"Service Pack: {os_info.CSDVersion}") print(f"Architecture: {os_info.OSArchitecture}") print(f"Free Physical Memory: {int(os_info.FreePhysicalMemory) / (1024**2):.2f} GB") print("\n--- Listing Running Processes (top 5) ---") # Get information about running processes (top 5) for process in c.Win32_Process()[:5]: print(f"Process: {process.Name}, ID: {process.ProcessId}, Status: {process.Status}") print("\n--- Listing Stopped Services (Auto Start) ---") # Find and list automatically starting services that are currently stopped for s in c.Win32_Service(StartMode="Auto", State="Stopped"): print(f"Service: {s.Caption}, State: {s.State}") except wmi.x_wmi as e: print(f"WMI Error: {e}") if "Access is denied" in str(e): print("Ensure the script is run with administrator privileges, or correct remote authentication.") elif "RPC server is unavailable" in str(e): print("Ensure the remote machine is reachable and the WMI service is running.") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
gotchaThe `wmi` library is strictly Windows-specific and will not function on Linux or macOS. It directly interacts with the Windows Management Instrumentation service and depends on the `pywin32` extensions, which are only available for Windows environments.
fix
Only use this library on Windows operating systems. For cross-platform WMI-like communication (from non-Windows to Windows), consider tools like `py-wmi-client` that implement client-side WMI protocols.
affects: All versions
gotchaAccessing WMI data, especially for system-level information or remote machines, frequently requires elevated privileges. Common errors like 'Access Denied' or 'RPC Server Unavailable' indicate insufficient permissions or network/firewall blocks.
fix
Run your Python script with administrator privileges. For remote connections, ensure the `user` and `password` parameters are correct, the WMI service is running on the target, and Windows Firewall allows WMI traffic (e.g., enable 'Remote Administration' firewall rule). DCOM configuration might also need adjustment for specific scenarios.
affects: All versions
gotchaQuerying `Win32_PerfFormattedData_*` classes directly through the `wmi` package can introduce significant performance overhead. This is particularly noticeable when collecting performance metrics frequently.
fix
For performance-critical monitoring, consider querying the `Win32_PerfRawData_*` classes and manually calculating the formatted values, or using direct `pywin32` COM calls to minimize overhead. Always explicitly specify only the required properties in your WMI queries to reduce data transfer.
affects: All versions
deprecatedThe `wmi` library's last release was in April 2020, indicating it is no longer under active development. While it remains functional, new features or compatibility fixes for future Python or Windows versions are unlikely. More modern alternatives like `PyMI` (which offers faster execution and no `pywin32` dependency) or specialized `windows-tools` modules are available.
fix
For new projects, evaluate more actively maintained libraries such as `PyMI` or components from `windows-tools`. For existing projects using `wmi`, be aware of the lack of ongoing support and consider migration if future compatibility or performance becomes a concern.
affects: All versions
Upgrade
Version history
1.5.1latest on PyPI · released Apr 28, 2020
Audit
Dependencies
pywin32requiredThe `wmi` library acts as a lightweight wrapper around the `pywin32` extensions to interact with the underlying COM and WMI APIs on Windows. It is a mandatory prerequisite.
Agent activity
37 hits · last 30 days
node
32
Meta
1
OpenAI (training)
1
Resources
wmi — pip install wmi · libregistry