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[source]

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()

namespaces

The list of available WMI namespaces

query

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

select

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

2.10.2. WmiNamespace

class windows.winobject.wmi.WmiNamespace(namespace)[source]

Bases: windows.generated_def.interfaces.IWbemServices, windows.winobject.wmi.WmiComInterface

An object to perform wmi request to a given namespace

DEFAULT_ENUM_FLAGS = 48L

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

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)[source]

Connect to namespace using user and password for authentification if given

Returns:WmiNamespace - The connected WmiNamespace
create_class_enum(superclass, flags=48L, deep=True)[source]

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
create_instance_enum(clsname, flags=48L, deep=True)[source]

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">]
delete_instance(instance, flags=0)[source]

TODO: Document

exec_method(obj, method, inparam, flags=0)[source]

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=48L, ctx=None)[source]

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

Returns:WmiEnumeration
get_object(path)[source]

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(0x2L))[source]

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)[source]

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)[source]

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[source]

Bases: windows.generated_def.interfaces.IWbemClassObject, windows.winobject.wmi.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

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)[source]

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

get_method(name)[source]

Return the information about the method name

Returns:WmiMethod
get_properties(system_properties=False)[source]

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)[source]

Retrieve the value of property name as a Variant

Returns:Variant
keys()[source]

The properties of the object (include system properties)

properties

The properties of the object (exclude system properties)

put(name, value)[source]

Set the property name to value

spawn_instance()[source]

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)[source]

Bases: windows.generated_def.interfaces.IWbemCallResult, windows.winobject.wmi.WmiComInterface

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

get_call_status(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffffL))[source]

The status of the call

get_result_object(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffffL))[source]

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

get_result_service(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffffL))[source]

The result as a WmiNamespace (not used yet)

get_result_string(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffffL))[source]

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

result

The result of the correct type based on self.result_type

value

current value

2.10.5. WmiEnumeration

class windows.winobject.wmi.WmiEnumeration[source]

Bases: windows.generated_def.interfaces.IEnumWbemClassObject, windows.winobject.wmi.WmiComInterface

Represent an enumeration of object that can be itered

DEFAULT_TIMEOUT = tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffffL)

The default timeout

__iter__()[source]

Return an iterator with DEFAULT_TIMEOUT

all()[source]

Return all elements in the enumeration as a list

Returns:[WmiObject] - A list of WmiObject
iter_timeout(timeout=None)[source]

Return an iterator with a custom timeout

next(timeout=None)[source]

Return the next object in the enumeration with timeout.

Raises:WindowsError(WBEM_S_TIMEDOUT) if timeout expire
Returns:WmiObject
value

current value