Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyMI-1.0.0.dev13.zip (214.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

PyMI-1.0.0.dev13-cp34-none-win_amd64.whl (254.7 kB view details)

Uploaded CPython 3.4Windows x86-64

PyMI-1.0.0.dev13-cp27-none-win32.whl (212.8 kB view details)

Uploaded CPython 2.7Windows x86

File details

Details for the file PyMI-1.0.0.dev13.zip.

File metadata

  • Download URL: PyMI-1.0.0.dev13.zip
  • Upload date:
  • Size: 214.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyMI-1.0.0.dev13.zip
Algorithm Hash digest
SHA256 44880b90e0a7d5273470e7bbca57eef451bed337125e85fc3877dade9f3b823f
MD5 6a14a0775bdb83f498d1ddad8b469ae3
BLAKE2b-256 8633f06d9b1dddd3c25bdc7832fd4bbacbcf9e3e57ed1bd01564fabe2eaa5ff0

See more details on using hashes here.

File details

Details for the file PyMI-1.0.0.dev13-cp34-none-win_amd64.whl.

File metadata

File hashes

Hashes for PyMI-1.0.0.dev13-cp34-none-win_amd64.whl
Algorithm Hash digest
SHA256 731effd79682d236fd718f0fac912b9516121afb1be07f5c7497f07bcf4674e3
MD5 5c895417144dc4610ddefd99cbc85d60
BLAKE2b-256 0d0205ff5abb6865f6502073c7a349436e20f4f9c62bcff8bbe38c51f9a0f8e5

See more details on using hashes here.

File details

Details for the file PyMI-1.0.0.dev13-cp27-none-win32.whl.

File metadata

File hashes

Hashes for PyMI-1.0.0.dev13-cp27-none-win32.whl
Algorithm Hash digest
SHA256 bd491904390b70ff9fba6d3e974eb8dc946068e05e6c5f75bbb5a13dac3563b2
MD5 2403c5ae1499ea1d7ca80cbd3a3f4765
BLAKE2b-256 d9aa2e7b483c036f650ab2cd1648485cfa3ba7db9c9d1df09be4aa99bd83f09d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page