Module wmi
[hide private]
[frames] | no frames]

Module wmi

source code

Classes [hide private]
  object
  ProvideConstants
A class which, when called on a win32com.client.Dispatch object, provides lazy access to constants defined in the typelib.
  x_wmi
  x_wmi_invalid_query
  x_wmi_timed_out
  x_wmi_no_namespace
  _wmi_method
A currying sort of wrapper around a WMI method name.
  _wmi_object
A lightweight wrapper round an OLE WMI object
  _wmi_event
Slight extension of the _wmi_object class to allow objects which are the result of events firing to return extra information such as the type of event.
  _wmi_class
Currying class to assist in issuing queries against a WMI namespace.
  _wmi_result
Simple, data only result for targeted WMI queries which request data only result classes via fetch_as_classes.
  _wmi_namespace
A WMI root of a computer system.
  _wmi_watcher
Helper class for WMI.watch_for below (qv)
Functions [hide private]
 
handle_com_error(error_info)
Convenience wrapper for displaying all manner of COM errors.
source code
 
from_1601(ns100) source code
 
from_time(year=None, month=None, day=None, hours=None, minutes=None, seconds=None, microseconds=None, timezone=None)
Convenience wrapper to take a series of date/time elements and return a WMI time of the form yyyymmddHHMMSS.mmmmmm+UUU.
source code
 
to_time(wmi_time)
Convenience wrapper to take a WMI datetime string of the form yyyymmddHHMMSS.mmmmmm+UUU and return a 9-tuple containing the individual elements, or None where string contains placeholder stars.
source code
 
_set(obj, attribute, value)
Helper function to add an attribute directly into the instance dictionary, bypassing possible __getattr__ calls
source code
 
connect(computer=".", impersonation_level="", authentication_level="", authority="", privileges="", moniker="", wmi=None, namespace="", suffix="", user="", password="", find_classes=True, debug=False)
The WMI constructor can either take a ready-made moniker or as many parts of one as are necessary.
source code
 
WMI(computer=".", impersonation_level="", authentication_level="", authority="", privileges="", moniker="", wmi=None, namespace="", suffix="", user="", password="", find_classes=True, debug=False)
The WMI constructor can either take a ready-made moniker or as many parts of one as are necessary.
source code
 
construct_moniker(computer=None, impersonation_level="Impersonate", authentication_level="Default", authority=None, privileges=None, namespace=None, suffix=None) source code
 
get_wmi_type(obj) source code
 
connect_server(server, namespace="", user="", password="", locale="", authority="", security_flags=0, named_value_set=None)
Return a remote server running WMI
source code
 
Registry(computer=None, impersonation_level="Impersonate", authentication_level="Default", authority=None, privileges=None, moniker=None) source code
 
machines_in_domain(domain_name) source code
Variables [hide private]
  True = 1
  False = 0
  __VERSION__ = "1.3.2"
  _DEBUG = 0
  obj = GetObject("winmgmts:")
  wbemErrInvalidQuery = obj._constants.wbemErrInvalidQuery
  wbemErrTimedout = obj._constants.wbemErrTimedout
  wbemFlagReturnImmediately = obj._constants.wbemFlagReturnImmed...
  wbemFlagForwardOnly = obj._constants.wbemFlagForwardOnly
  BASE = datetime.datetime(1601, 1, 1)
  WMI_EXCEPTIONS = {wbemErrInvalidQuery: x_wmi_invalid_query, wb...
  PROTOCOL = "winmgmts:"
  IMPERSONATION_LEVEL = "impersonate"
  AUTHENTICATION_LEVEL = "default"
  NAMESPACE = "root/cimv2"
Function Details [hide private]

handle_com_error(error_info)

source code 

Convenience wrapper for displaying all manner of COM errors. Raises a x_wmi exception with more useful information attached

@param error_info The structure attached to a pywintypes.com_error

from_time(year=None, month=None, day=None, hours=None, minutes=None, seconds=None, microseconds=None, timezone=None)

source code 

Convenience wrapper to take a series of date/time elements and return a WMI time of the form yyyymmddHHMMSS.mmmmmm+UUU. All elements may be int, string or omitted altogether. If omitted, they will be replaced in the output string by a series of stars of the appropriate length.

@param year The year element of the date/time @param month The month element of the date/time @param day The day element of the date/time @param hours The hours element of the date/time @param minutes The minutes element of the date/time @param seconds The seconds element of the date/time @param microseconds The microseconds element of the date/time @param timezone The timeezone element of the date/time

to_time(wmi_time)

source code 

Convenience wrapper to take a WMI datetime string of the form yyyymmddHHMMSS.mmmmmm+UUU and return a 9-tuple containing the individual elements, or None where string contains placeholder stars.

@param wmi_time The WMI datetime string in yyyymmddHHMMSS.mmmmmm+UUU format

@return A 9-tuple of (year, month, day, hours, minutes, seconds, microseconds, timezone)

_set(obj, attribute, value)

source code 

Helper function to add an attribute directly into the instance dictionary, bypassing possible __getattr__ calls

@param obj Any python object @param attribute String containing attribute name @param value Any python object

connect(computer=".", impersonation_level="", authentication_level="", authority="", privileges="", moniker="", wmi=None, namespace="", suffix="", user="", password="", find_classes=True, debug=False)

source code 

The WMI constructor can either take a ready-made moniker or as many parts of one as are necessary. Eg,

<pre class="code"> c = wmi.WMI (moniker="winmgmts:{impersonationLevel=Delegate}//remote")

# or

c = wmi.WMI (computer="remote", privileges=["!RemoteShutdown", "Security"]) </pre>

I daren't link to a Microsoft URL; they change so often. Try Googling for WMI construct moniker and see what it comes back with.

For complete control, a named argument "wmi" can be supplied, which should be a SWbemServices object, which you create yourself. Eg,

<pre class="code"> loc = win32com.client.Dispatch("WbemScripting.SWbemLocator") svc = loc.ConnectServer(...) c = wmi.WMI(wmi=svc) </pre>

This is the only way of connecting to a remote computer with a different username, as the moniker syntax does not allow specification of a user name.

If the "wmi" parameter is supplied, all other parameters are ignored.

WMI(computer=".", impersonation_level="", authentication_level="", authority="", privileges="", moniker="", wmi=None, namespace="", suffix="", user="", password="", find_classes=True, debug=False)

source code 

The WMI constructor can either take a ready-made moniker or as many parts of one as are necessary. Eg,

<pre class="code"> c = wmi.WMI (moniker="winmgmts:{impersonationLevel=Delegate}//remote")

# or

c = wmi.WMI (computer="remote", privileges=["!RemoteShutdown", "Security"]) </pre>

I daren't link to a Microsoft URL; they change so often. Try Googling for WMI construct moniker and see what it comes back with.

For complete control, a named argument "wmi" can be supplied, which should be a SWbemServices object, which you create yourself. Eg,

<pre class="code"> loc = win32com.client.Dispatch("WbemScripting.SWbemLocator") svc = loc.ConnectServer(...) c = wmi.WMI(wmi=svc) </pre>

This is the only way of connecting to a remote computer with a different username, as the moniker syntax does not allow specification of a user name.

If the "wmi" parameter is supplied, all other parameters are ignored.

connect_server(server, namespace="", user="", password="", locale="", authority="", security_flags=0, named_value_set=None)

source code 
Return a remote server running WMI

  server - name of the server
  namespace - namespace to connect to: defaults to whatever's defined as default
  user - username to connect as, either local or domain (dom
ame or user@domain for XP)
  password: leave blank to use current context
  locale: desired locale in form MS_XXXX (eg MS_409 for Am En)
  authority: either "Kerberos:" or an NT domain. Not needed if included in user
  security_flags: if 0, connect will wait forever; if 0x80, connect will timeout at 2 mins
  named_value_set: typically empty, otherwise a context-specific SWbemNamedValueSet

  <pre class="code">
  c = wmi.WMI (wmi=wmi.connect_server (server="remote_machine", user="myname", password="mypassword"))
  </pre>
  


Variables Details [hide private]

wbemFlagReturnImmediately

Value:
obj._constants.wbemFlagReturnImmediately

WMI_EXCEPTIONS

Value:
{wbemErrInvalidQuery: x_wmi_invalid_query, wbemErrTimedout: x_wmi_time\
d_out}