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 wmiVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
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.