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
WmiNamespaceby name- Example:
>>> windows.system.wmi[r"root\SecurityCenter2"] <WmiNamespace "root\SecurityCenter2">
- 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)[source]¶
Bases:
IWbemServices,WmiComInterfaceAn 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().
- classmethod connect(namespace, user=None, password=None)[source]¶
Connect to
namespaceusinguserandpasswordfor authentification if given- Returns:
WmiNamespace- The connectedWmiNamespace
- create_class_enum(superclass, flags=48, deep=True)[source]¶
Enumerate the classes in the
namespacethat matchsuperclass. ifsuperclassis None will enumerate all top-level class.deepallow to returns all subclasses- Returns:
- create_instance_enum(clsname, flags=48, deep=True)[source]¶
Enumerate the instances of
clsname. Deep allows to enumerate the instance of subclasses as well- Returns:
- 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">]
- exec_method(obj, method, inparam, flags=0)[source]¶
Exec method named on
objectwithinparam.- params obj:
The
WmiObjector path of the object the call apply to- params method:
The name of the method to call on the object
- params inparam:
The
WmiObjectrepresenting the input parameters and retrieve usingWmiObject.get_method()
- Returns:
WmiCallResult(object)if flag WBEM_FLAG_RETURN_IMMEDIATELY was passed- Returns:
WmiObjectthe 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)[source]¶
Execute a WQL query with custom flags and returns a :
WmiEnumerationthat can be used to iter the result with timeouts- Returns:
- from_param()¶
Convert a Python object into a function call parameter.
- get_object(path)[source]¶
Return the object matching
path. Ifpathis a class name return the class object``- Returns:
- put_instance(instance, flags=tag_WBEM_CHANGE_FLAG_TYPE.WBEM_FLAG_CREATE_ONLY(0x2))[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
WmiObjectmatchingquery.This API is the simple one, if you need timeout or complexe feature see
exec_query()
- select(clsname, deep=True)[source]¶
Return the list of
WmiObjectthat are instance ofclsname. Deep has the same meaning as increate_instance_enum().This API is the simple one, if you need timeout or complexe feature see
create_instance_enum()
- value¶
current value
2.10.3. WmiObject¶
- class windows.winobject.wmi.WmiObject[source]¶
Bases:
IWbemClassObject,WmiComInterfaceThe WmiObject (which wrap
IWbemClassObject) contains and manipulates both class definitions and class object instances. Can be used as a mapping to access properties.- __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
nametovalue
- from_param()¶
Convert a Python object into a function call parameter.
- property genus¶
The genus of the object.
- Returns:
WBEM_GENUS_CLASS(0x1L)if theWmiObjectis a Class andWBEM_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_properties(system_properties=False)[source]¶
Return the list of properties names available for the current object. If
system_propertiesisFalseproperty names begining with_are ignored.- Returns:
[
str] – A list of string
- property properties¶
The properties of the object (exclude system properties)
- spawn_instance()[source]¶
Create a new object of the class represented by the current
WmiObject- Returns:
- value¶
current value
2.10.4. WmiCallResult¶
- class windows.winobject.wmi.WmiCallResult(result_type=None, namespace_name=None)[source]¶
Bases:
IWbemCallResult,WmiComInterfaceThe 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))[source]¶
The status of the call
- get_result_object(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff))[source]¶
The result as a
WmiObject(returned byWmiNamespace.exec_method())
- get_result_service(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff))[source]¶
The result as a
WmiNamespace(not used yet)
- get_result_string(timeout=tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff))[source]¶
The result as a
WmiObject(returned byWmiNamespace.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[source]¶
Bases:
IEnumWbemClassObject,WmiComInterfaceRepresent an enumeration of object that can be itered
- DEFAULT_TIMEOUT = tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE(0xffffffff)¶
The default timeout
- from_param()¶
Convert a Python object into a function call parameter.
- next(timeout=None)[source]¶
Return the next object in the enumeration with timeout.
- Raises:
WindowsError(WBEM_S_TIMEDOUT)if timeout expire- Returns:
- value¶
current value