Module wmi :: Class _wmi_namespace
[hide private]
[frames] | no frames]

Class _wmi_namespace

source code

A WMI root of a computer system. The classes attribute holds a list
of the classes on offer. This means you can explore a bit with
things like this:

<pre class="code">
c = wmi.WMI ()
for i in c.classes:
  if "user" in i.lower ():
    print i
</pre>

Instance Methods [hide private]
 
__init__(self, namespace, find_classes) source code
 
__repr__(self) source code
 
__str__(self) source code
 
get(self, moniker) source code
 
handle(self)
The raw OLE object representing the WMI namespace
source code
 
subclasses_of(self, root="", regex=r".*") source code
 
instances(self, class_name)
Return a list of instances of the WMI class.
source code
 
new(self, wmi_class, **kwargs)
This is now implemented by a call to _wmi_namespace.new (qv)
source code
 
new_instance_of(self, wmi_class, **kwargs)
This is now implemented by a call to _wmi_namespace.new (qv)
source code
 
_raw_query(self, wql)
Execute a WQL query and return its raw results.
source code
 
query(self, wql, instance_of=None, fields=[])
Perform an arbitrary query against a WMI object, and return a list of _wmi_object representations of the results.
source code
 
fetch_as_classes(self, wmi_classname, fields=(), **where_clause)
Build and execute a wql query to fetch the specified list of fields from the specified wmi_classname + where_clause, then return the results as a list of simple class instances with attributes matching fields_list.
source code
 
fetch_as_lists(self, wmi_classname, fields, **where_clause)
Build and execute a wql query to fetch the specified list of fields from the specified wmi_classname + where_clause, then return the results as a list of lists whose values correspond fields_list.
source code
 
watch_for(self, raw_wql=None, notification_type="operation", wmi_class=None, delay_secs=1, **where_clause)
Set up an event tracker on a WMI event.
source code
 
__getattr__(self, attribute)
Offer WMI classes as simple attributes.
source code
 
_cached_classes(self, class_name)
Standard caching helper which keeps track of classes already retrieved by name and returns the existing object if found.
source code
 
_getAttributeNames(self)
Return list of classes for IPython completion engine
source code
Method Details [hide private]

instances(self, class_name)

source code 
Return a list of instances of the WMI class. This is
 (probably) equivalent to querying with no qualifiers.

<pre class="code">
system.instances ("Win32_LogicalDisk")
# should be the same as
system.Win32_LogicalDisk ()
</pre>

_raw_query(self, wql)

source code 
Execute a WQL query and return its raw results.  Use the flags
 recommended by Microsoft to achieve a read-only, semi-synchronous
 query where the time is taken while looping through. Should really
 be a generator, but ...
NB Backslashes need to be doubled up.

fetch_as_classes(self, wmi_classname, fields=(), **where_clause)

source code 

Build and execute a wql query to fetch the specified list of fields from the specified wmi_classname + where_clause, then return the results as a list of simple class instances with attributes matching fields_list.

If fields is left empty, select * and pre-load all class attributes for each class returned.

watch_for(self, raw_wql=None, notification_type="operation", wmi_class=None, delay_secs=1, **where_clause)

source code 
Set up an event tracker on a WMI event. This function
returns an wmi_watcher which can be called to get the
next event. eg,

<pre class="code">
c = wmi.WMI ()

raw_wql = "SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_Process'"
watcher = c.watch_for (raw_wql=raw_wql)
while 1:
  process_created = watcher ()
  print process_created.Name

# or
 
watcher = c.watch_for (
  notification_type="Creation",
  wmi_class="Win32_Process",
  delay_secs=2,
  Name='calc.exe'
)
calc_created = watcher ()
</pre>

Now supports timeout on the call to watcher, eg:

<pre class="code">
import pythoncom
import wmi
c = wmi.WMI (privileges=["Security"])
watcher1 = c.watch_for (
  notification_type="Creation",
  wmi_class="Win32_NTLogEvent",
  Type="error"
)
watcher2 = c.watch_for (
  notification_type="Creation",
  wmi_class="Win32_NTLogEvent",
  Type="warning"
)

while 1:
  try:
    error_log = watcher1 (500)
  except wmi.x_wmi_timed_out:
    pythoncom.PumpWaitingMessages ()
  else:
    print error_log

  try:
    warning_log = watcher2 (500)
  except wmi.x_wmi_timed_out:
    pythoncom.PumpWaitingMessages ()
  else:
    print warning_log
</pre>

__getattr__(self, attribute)
(Qualification operator)

source code 

Offer WMI classes as simple attributes. Pass through any untrapped unattribute to the underlying OLE object. This means that new or unmapped functionality is still available to the module user.

_cached_classes(self, class_name)

source code 

Standard caching helper which keeps track of classes already retrieved by name and returns the existing object if found. If this is the first retrieval, store it and pass it back