# 2.10. WMI – Make request to WMI — PythonForWindows 1.0.3 documentation

# 2.10. WMI – Make request to WMI

The `WmiManager` is accessible via `windows.system.wmi`

Note

See sample WMI

## 2.10.1. WmiManager

class windows.winobject.wmi.WmiManager

  The main WMI class exposed, used to list and access differents WMI namespace, can be used as a dict to access `WmiNamespace` by name

  Example:

        >>> windows.system.wmi["root\SecurityCenter2"]
        <WmiNamespace "root\SecurityCenter2">

  DEFAULT_NAMESPACE = 'root\\cimv2'

    The default namespace for `select()` & `query()`

  property namespaces

    The list of available WMI namespaces

  property query

    `WmiRequester.query()` for default WMI namespace ‘root\cimv2’

  property select

    `WmiRequester.select()` for default WMI namespace ‘root\cimv2’

## 2.10.2. WmiNamespace

class windows.winobject.wmi.WmiNamespace(namespace)

  Bases: `IWbemServices`, `WmiComInterface`

  An object to perform wmi request to a given `namespace`

  DEFAULT_ENUM_FLAGS = 48

    The defauls flags used for enumeration. `(WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY)`

  property classes

    The list of classes in the namespace. This a a wrapper arround `create_class_enum()`.

    Returns:

      [`WmiObject`] - A list of `WmiObject`

  classmethod connect(namespace, user=None, password=None)

    Connect to `namespace` using `user` and `password` for authentification if given

    Returns:

      `WmiNamespace` - The connected `WmiNamespace`

  create_class_enum(superclass, flags=48, deep=True)

    Enumerate the classes in the `namespace` that match `superclass`. if `superclass` is None will enumerate all top-level class. `deep` allow to returns all subclasses

    Returns:

      `WmiEnumeration`

    Note

    See https://docs.microsoft.com/en-us/windows/desktop/api/wbemcli/nf-wbemcli-iwbemservices-createclassenum

  create_instance_enum(clsname, flags=48, deep=True)

    Enumerate the instances of `clsname`. Deep allows to enumerate the instance of subclasses as well

    Returns:

      `WmiEnumeration`

    Example:

          >>> windows.system.wmi["root\subscription"].create_instance_enum("__EventConsumer", deep=False).all()
          []
          >>> windows.system.wmi["root\subscription"].create_instance_enum("__EventConsumer", deep=True).all()
          [<WmiObject instance of "NTEventLogEventConsumer">]

    Note

    See https://docs.microsoft.com/en-us/windows/desktop/api/wbemcli/nf-wbemcli-iwbemservices-createinstanceenum

  delete_instance(instance, flags=0)

    TODO: Document

  exec_method(obj, method, inparam, flags=0)

    Exec method named on `object` with `inparam`.

    > params obj:

    >   The `WmiObject` or path of the object the call apply to

    > params method:

    >   The name of the method to call on the object

    > params inparam:

    >   The `WmiObject` representing the input parameters and retrieve using `WmiObject.get_method()`

    Returns:

      `WmiCallResult` `(object)` if flag WBEM_FLAG_RETURN_IMMEDIATELY was passed

    Returns:

      `WmiObject` the outparam object if flag WBEM_FLAG_RETURN_IMMEDIATELY was NOT passed

    Note

    This API will lakely change to better wrap with WmiObject/inparam/Dict & co

  exec_query(query, flags=48, ctx=None)

    Execute a WQL query with custom flags and returns a :`WmiEnumeration` that can be used to iter the result with timeouts

    Returns:

      `WmiEnumeration`

  from_param()

    Convert a Python object into a function call parameter.

  get_object(path)

    Return the object matching `path`. If `path` is a class name return the class object``

    Returns:

      `WmiObject`

  put_instance(instance, flags=tag_WBEM_CHANGE_FLAG_TYPE.WBEM_FLAG_CREATE_ONLY(0x2))

    Creates or updates an instance of an existing class in the namespace

    Returns:

      `WmiCallResult` `(string)` - Used to retrieve the string representing the path of the object created/updated

  query(query)

    Return the list of `WmiObject` matching `query`.

    This API is the simple one, if you need timeout or complexe feature see `exec_query()`

    Returns:

      [`WmiObject`] - A list of `WmiObject`

  select(clsname, deep=True)

    Return the list of `WmiObject` that are instance of `clsname`. Deep has the same meaning as in `create_instance_enum()`.

    This API is the simple one, if you need timeout or complexe feature see `create_instance_enum()`

    Returns:

      [`WmiObject`] - A list of `WmiObject`

  value

    current value

## 2.10.3. WmiObject

class windows.winobject.wmi.WmiObject

  Bases: `IWbemClassObject`, `WmiComInterface`

  The WmiObject (which wrap `IWbemClassObject`) contains and manipulates both class definitions and class object instances. Can be used as a mapping to access properties.

  __call__()

    Create a new object of the class represented by the current `WmiObject`

    Returns:

      `WmiObject`

  __getitem__(name)

    Return the value of the property `name`. The return value depends of the type of the property and can vary

  __setitem__(name, value)

    Set the property `name` to `value`

  from_param()

    Convert a Python object into a function call parameter.

  property genus

    The genus of the object.

    Returns:

      `WBEM_GENUS_CLASS(0x1L)` if the `WmiObject` is a Class and `WBEM_GENUS_INSTANCE(0x2L)` for instances and events.

  get(name)

    Return the value of the property `name`. The return value depends of the type of the property and can vary

  get_method(name)

    Return the information about the method `name`

    Returns:

      `WmiMethod`

  get_properties(system_properties=False)

    Return the list of properties names available for the current object. If `system_properties` is `False` property names begining with `_` are ignored.

    Returns:

      [`str`] – A list of string

  get_variant(name)

    Retrieve the value of property `name` as a `Variant`

    Returns:

      `Variant`

  keys()

    The properties of the object (include system properties)

  property properties

    The properties of the object (exclude system properties)

  put(name, value)

    Set the property `name` to `value`

  spawn_instance()

    Create a new object of the class represented by the current `WmiObject`

    Returns:

      `WmiObject`

  value

    current value

## 2.10.4. WmiCallResult

class windows.winobject.wmi.WmiCallResult(result_type=None, namespace_name=None)

  Bases: `IWbemCallResult`, `WmiComInterface`

  The result of a WMI call/query. Real result value type depends of the context

  from_param()

    Convert a Python object into a function call parameter.

  get_call_status(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff))

    The status of the call

  get_result_object(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff))

    The result as a `WmiObject` (returned by `WmiNamespace.exec_method()`)

  get_result_service(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff))

    The result as a `WmiNamespace` (not used yet)

  get_result_string(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff))

    The result as a `WmiObject` (returned by `WmiNamespace.put_instance()`)

  property result

    The result of the correct type based on `self.result_type`

  value

    current value

## 2.10.5. WmiEnumeration

class windows.winobject.wmi.WmiEnumeration

  Bases: `IEnumWbemClassObject`, `WmiComInterface`

  Represent an enumeration of object that can be itered

  DEFAULT_TIMEOUT = tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff)

    The default timeout

  __iter__()

    Return an iterator with `DEFAULT_TIMEOUT`

  all()

    Return all elements in the enumeration as a list

    Returns:

      [`WmiObject`] - A list of `WmiObject`

  from_param()

    Convert a Python object into a function call parameter.

  iter_timeout(timeout=None)

    Return an iterator with a custom `timeout`

  next(timeout=None)

    Return the next object in the enumeration with timeout.

    Raises:

      `WindowsError(WBEM_S_TIMEDOUT)` if timeout expire

    Returns:

      `WmiObject`

  value

    current value