Windows Management Infrastructure API for Python.
Project description
This project provides a Python native module wrapper over the Windows Management Infrastructure (MI) API [1].
Works with Python 2.7 and 3.x on any Windows version which supports the MI API, both x86 and x64.
It includes also a drop-in replacement for the Python WMI [2] module, proving much faster execution times and no dependency on pywin32.
Installation
Pip is the preferred way to install PyMI. Pre-compiled binary wheels are available on Pypi [3]:
pip install PyMI
Usage
This project can be used either with a lower level interface that reflects the underlying MI API structure or with the higher level (and slightly slower) WMI module replacement.
MI module basic usage
Here’s a simple example which enumerates all processes and kills any instance of “KillerRabbitOfCaerbannog.exe”.
import mi with mi.Application() as a: with a.create_session(protocol=mi.PROTOCOL_WMIDCOM) as s: proc_name = u'notepad.exe' with s.exec_query( u"root\\cimv2", u"select * from Win32_Process") as q: i = q.get_next_instance() while i is not None: if i[u'name'].lower() == u"KillerRabbitOfCaerbannog.exe": cls = i.get_class() # Prepare parameters params = a.create_method_params(cls, u"Terminate") # Exit code params['reason'] = 10 # Invoke method with s.invoke_method(i, u"Terminate", params) as op: op.get_next_instance() i = q.get_next_instance()
WMI module basic usage
And here’s the same example written using the WMI module replacement, which provides a simpler and higher level interface over the mi API:
import wmi conn = wmi.WMI() for p in conn.Win32_Process(): if p.Name == u"KillerRabbitOfCaerbannog.exe": p.Terminate(reason=10)
Build
Open the provided PyMI.sln solution in Visual Studio 2015 [4], choose your target Python version / platform and build. Wheel packages are automatically generated in the dist folder for release builds.
Note: the target Python version must be present. The Python path can be customized by setting the corresponding PythonDir* user macro, e.g. PythonDir_34_x64.
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for PyMI-1.0.2.dev2-cp34-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5f319d3b665d7f3ad61da1182dbb54d225243adb3e5cf50cbc0ac42a81f73bf |
|
MD5 | 7da940c3e3c48cc4213b631993cdcb22 |
|
BLAKE2b-256 | fb61924008b4b5c6540e307a6648e7d0e48bb66311e9db4fadc733e8eb7c4949 |
Hashes for PyMI-1.0.2.dev2-cp27-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a501430d19218532288745f81e50d3d7a5fc02577926fbd5d0dd8f92220b3a9 |
|
MD5 | 5ea42f3f6742a60265d3310910e799c2 |
|
BLAKE2b-256 | 0b928b447bc473a0e0fbe192f94f5bd183aedcdc8c6aef8306574eefd3f8889e |
Hashes for PyMI-1.0.2.dev2-cp27-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5056996adcd8cd23fa500e3da3fde3e63fcb9762dad7fea5f538bdbc39336050 |
|
MD5 | 35670fc17b9e0e4bc3230eb7afb425b5 |
|
BLAKE2b-256 | 0b8e7a694ec397246c63e33e17f79bd533f7fddb1ef7337fc83f51adc25d0756 |