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">
-
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 ofWmiObject
-
classmethod
connect
(namespace, user=None, password=None)[source]¶ Connect to
namespace
usinguser
andpassword
for authentification if givenReturns: WmiNamespace
- The connectedWmiNamespace
-
create_class_enum
(superclass, flags=48L, deep=True)[source]¶ Enumerate the classes in the
namespace
that matchsuperclass
. ifsuperclass
is None will enumerate all top-level class.deep
allow to returns all subclassesReturns: WmiEnumeration
-
create_instance_enum
(clsname, flags=48L, deep=True)[source]¶ Enumerate the instances of
clsname
. Deep allows to enumerate the instance of subclasses as wellReturns: 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">]
-
exec_method
(obj, method, inparam, flags=0)[source]¶ Exec method named on
object
withinparam
.params obj: The WmiObject
or path of the object the call apply toparams method: The name of the method to call on the object params inparam: The WmiObject
representing the input parameters and retrieve usingWmiObject.get_method()
Returns: WmiCallResult
(object)
if flag WBEM_FLAG_RETURN_IMMEDIATELY was passedReturns: WmiObject
the outparam object if flag WBEM_FLAG_RETURN_IMMEDIATELY was NOT passedNote
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 timeoutsReturns: WmiEnumeration
-
get_object
(path)[source]¶ Return the object matching
path
. Ifpath
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
matchingquery
.This API is the simple one, if you need timeout or complexe feature see
exec_query()
Returns: [ WmiObject
] - A list ofWmiObject
-
select
(clsname, deep=True)[source]¶ Return the list of
WmiObject
that 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()
Returns: [ WmiObject
] - A list ofWmiObject
-
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.-
__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
tovalue
-
genus
¶ The genus of the object.
Returns: WBEM_GENUS_CLASS(0x1L)
if theWmiObject
is 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_properties
isFalse
property names begining with_
are ignored.Returns: [ str
] – A list of string
-
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: 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 byWmiNamespace.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 byWmiNamespace.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
-
all
()[source]¶ Return all elements in the enumeration as a list
Returns: [ WmiObject
] - A list ofWmiObject
-
next
(timeout=None)[source]¶ Return the next object in the enumeration with timeout.
Raises: WindowsError(WBEM_S_TIMEDOUT)
if timeout expireReturns: WmiObject
-
value
¶ current value
-