name : wmi.pyc
�
LTfMc@s�dZdZZeaddlZddlZddlZddlZddl	Z	ddl
mZmZddl
Z
d�Zdefd��YZdefd	��YZed
�Zee�ejjZejjZejjZejjZdefd��YZd
efd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZieee�6eee�6ed6ed6ed6Z e!d�Z"ejddd�Z#d�Z$e!e!e!e!e!e!e!e!d �Z%d!�Z&d"�Z'd#fd$��YZ(d%efd&��YZ)d'fd(��YZ*d)e*fd*��YZ+d+e*fd,��YZ,d-fd.��YZ-d/fd0��YZ.d1fd2��YZ/d
Z0d3d3d3d3d3d3e!d3d3d3d3eed4�
Z1e1Z2e!e!e!e!e!e!e!d5�Z3d6�Z4d3d3d3d3d3d3d3d7e!d8�	Z5e!d9d:e!e!e!d;�Z6e7d<kr�e2�Z8xVe8j9�D]HZ:d=e:j;fGHx1e8j<�D]#Z=e=j>e=j?e=j@p�d3fGHq�Wq�WndS(>s�

Windows Management Instrumentation (WMI) is Microsoft's answer to
the DMTF's Common Information Model. It allows you to query just
about any conceivable piece of information from any computer which
is running the necessary agent and over which have you the
necessary authority.

Since the COM implementation doesn't give much away to Python
programmers, I've wrapped it in some lightweight classes with
some getattr / setattr magic to ease the way. In particular:

* The :class:`_wmi_namespace` object itself will determine its classes
  and allow you to return all instances of any of them by
  using its name as an attribute::

    disks = wmi.WMI ().Win32_LogicalDisk ()

* In addition, you can specify what would become the WHERE clause
  as keyword parameters::

    fixed_disks = wmi.WMI ().Win32_LogicalDisk (DriveType=3)

* The objects returned by a WMI lookup are wrapped in a Python
  class which determines their methods and classes and allows
  you to access them as though they were Python classes. The
  methods only allow named parameters::

    for p in wmi.WMI ().Win32_Process (Name="notepad.exe"):
      p.Terminate (Result=1)

* Doing a print on one of the WMI objects will result in its
  `GetObjectText\_` method being called, which usually produces
  a meaningful printout of current values.
  The repr of the object will include its full WMI path,
  which lets you get directly to it if you need to.

* You can get the associators and references of an object as
  a list of python objects by calling the associators () and
  references () methods on a WMI Python object::

    for p in wmi.WMI ().Win32_Process (Name="notepad.exe"):
      for r in p.references ():
        print r

  ..  note::
      Don't do this on a Win32_ComputerSystem object; it will
      take all day and kill your machine!


* WMI classes (as opposed to instances) are first-class
  objects, so you can get hold of a class, and call
  its methods or set up a watch against it::

    process = wmi.WMI ().Win32_Process
    process.Create (CommandLine="notepad.exe")

* To make it easier to use in embedded systems and py2exe-style
  executable wrappers, the module will not force early Dispatch.
  To do this, it uses a handy hack by Thomas Heller for easy access
  to constants.

Typical usage will be::

  import wmi

  vodev1 = wmi.WMI ("vodev1")
  for disk in vodev1.Win32_LogicalDisk ():
    if disk.DriveType == 3:
      space = 100 * long (disk.FreeSpace) / long (disk.Size)
      print "%s has %d%% free" % (disk.Name, space)

Many thanks, obviously to Mark Hammond for creating the win32all
extensions, but also to Alex Martelli and Roger Upole, whose
c.l.py postings pointed me in the right direction.
Thanks especially in release 1.2 to Paul Tiemann for his code
contributions and robust testing.
s1.4.9i����N(t	GetObjecttDispatchcCs%tjdtjd|��\}|S(s�Convert a (possibly signed) long to unsigned hex. Useful
  when converting a COM error code to the more conventional
  8-digit hex::

    print "%08X" % signed_to_unsigned (-2147023174)
  tLtl(tstructtunpacktpack(tsignedtunsigned((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytsigned_to_unsigned[s!tSelfDeprecatingDictcBseeZdZeee��jee��Zd�Z	d�Z
d�Zd�Zd�Z
d�ZRS(s<Provides for graceful degradation of objects which
  are currently dictionaries (and therefore accessed via
  `.keys`, `.items`, etc.) into lists. Wraps an existing
  `dict` and allows it to be addressed as a `dict` or as a
  `list` during an interregnum, issuing a `DeprecationWarning`
  if accessed as a `dict`.
  cCs%t|�|_t|j�|_dS(N(tdicttlist(tselftdictlike((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__init__pscCsC||jkr/tjdt�t|j|�St|j|�SdS(Ns2In future this will be a list and not a dictionary(t	dict_onlytwarningstwarntDeprecationWarningtgetattrRR(R
t	attribute((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__getattr__tscCs
t|j�S(N(titerR(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__iter__{scCs
t|j�S(N(tstrR(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__str__~scCs
t|j�S(N(treprR(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__repr__�scCs/y|j|SWntk
r*|j|SXdS(N(Rt	TypeErrorR(R
titem((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__getitem__�s
(t__name__t
__module__t__doc__tsettdirRt
differenceRRRRRRRR(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR
es!					tProvideConstantscBs eZdZd�Zd�ZRS(s�When called on a ``win32com.client.Dispatch`` object,
  provides lazy access to constants defined in the typelib.
  They can then be accessed as attributes of the :attr:`_constants`
  property. (From Thomas Heller on c.l.py).
  cCs3||jd<|jj�j�dj�|_dS(Nt
_constantsi(t__dict__t_oleobj_tGetTypeInfotGetContainingTypeLibtGetTypeCompt_ProvideConstants__typecomp(R
tcomobj((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s
cCsc|jd�r-|jd�r-t|��n|jj|�}|dsXt|��n|djS(Nt__ii(t
startswithtendswithtAttributeErrorR-tBindtvalue(R
tnametresult((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s
(R R!R"RR(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR&�s	s	winmgmts:tx_wmicBs&eZdZddd�Zd�ZRS(s�Ancestor of all wmi-related exceptions. Keeps track of
  an info message and the underlying COM error if any, exposed
  as the :attr:`com_error` attribute.
  tcCs||_||_dS(N(tinfot	com_error(R
R9R:((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s	cCs d|jpd|jpdfS(Ns<x_wmi: %s %s>sUnexpected COM Errors(no underlying exception)(R9R:(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�sN(R R!R"tNoneRR(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR7�stx_wmi_invalid_querycBseZdZRS(s/Raised when a WMI returns `wbemErrInvalidQuery`(R R!R"(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR<�stx_wmi_timed_outcBseZdZRS(sRaised when a watcher times out(R R!R"(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR=�stx_wmi_no_namespacecBseZdZRS(sWRaised when an attempt is made to query or watch
  from a class without a namespace.
  (R R!R"(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR>�stx_access_deniedcBseZdZRS(sRaised when WMI raises 80070005(R R!R"(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR?�stx_wmi_authenticationcBseZdZRS(s\Raised when an invalid combination of authentication properties is attempted when connecting(R R!R"(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR@�stx_wmi_uninitialised_threadcBseZdZRS(sxRaised when WMI returns 800401E4 on connection, usually
  indicating that no COM threading model has been initialised
  (R R!R"(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRA�slll�cCs|dkr$tj�\}}}n|j\}}}}t|�}dt|�|fg}d}|r�|\}}	}
}}}t|�}|jd|	�|jdt|�|
p�dj�f�nx6tj	�D]"\}
}|
||fkr�Pq�q�Wt
}|d|��dS(s�Convenience wrapper for displaying all manner of COM errors.
  Raises a :exc:`x_wmi` exception with more useful information attached

  :param err: The structure attached to a `pywintypes.com_error`
  s%s - %ss  Error in: %ss	  %s - %sR8R:N(R;tsystexc_infotargsR	thextappendtstriptWMI_EXCEPTIONStitemsR7(terrt_thresult_codethresult_nametadditional_infotparameter_in_errortexception_stringtscodetwcodetsource_of_errorterror_descriptiont	whlp_filetwhlp_contextt
error_codetklass((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pythandle_com_error�s ,iAicCsttjdt|�d�S(Ntmicrosecondsi
(tBASEtdatetimet	timedeltatint(tns100((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt	from_1601�sc
Cs�d�}d}	|	||d�7}	|	||d�7}	|	||d�7}	|	||d�7}	|	||d�7}	|	||d�7}	|	d7}	|	||d�7}	|dkr�|	d7}	n|	d	7}	t|�}|	||d
�7}	|	S(sConvenience 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

  :returns: A WMI datetime string of the form: `yyyymmddHHMMSS.mmmmmm+UUU`
  cSs.|dkrd|St|�j|d�SdS(Nt*t0(R;Rtrjust(titlength((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytstr_or_stars	sR8iit.iit+t-i(tabs(
tyeartmonthtdaythourstminutestsecondsRZttimezoneRftwmi_time((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt	from_time�s 	


c
Cs�d�}||dd�}||dd�}||dd�}||dd�}||dd�}||dd�}||d	d
�}|d}	|	dkr�d
}	n||||||||	fS(szConvenience 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

  :returns: A 9-tuple of (year, month, day, hours, minutes, seconds, microseconds, timezone)
  cSs.yt|||!�SWntk
r)dSXdS(N(R^t
ValueErrorR;(tststarttend((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytint_or_none+s
iiiii
iiiiis***N(R;(
RrRxRkRlRmRnRoRpRZRq((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytto_time!s
	
	cCs||j|<dS(s�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
  N(R((tobjRR4((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt_set>st_wmi_methodcBs)eZdZd�Zd�Zd�ZRS(s�A currying sort of wrapper around a WMI method name. It
  abstract's the method's parameters and can be called like
  a normal Python object passing in the parameter values.

  Output parameters are returned from the call as a tuple.
  In addition, the docstring is set up as the method's
  signature, including an indication as to whether any
  given parameter is expecting an array, and what
  special privileges are required to call the method.
  c		Cs�y�t|�|_|j|�|_i|_x'|jjD]}|j|j|j<q:Wdj|jj	dg��|_
|jj|_|jj
|_|jd	kr�g|_n.g|jjD]}|j|jf^q�|_|jd	kr�g|_n.g|jjD]}|j|jf^q|_d|djg|jD]\}}|d
|^q>�djg|jD]\}}|d|^qn�f}|jj	dg�}|r�|ddj|�7}n||_Wntjk
r�t�nXd	S(s�
    :param ole_object: The WMI class/instance whose method is to be called
    :param method_name: The name of the method to be called
    s
tMappingStringss%s (%s) => (%s)s, R8s[]t
Privilegess
 | Needs: N(R8s[](R8s[](Rt
ole_objecttMethods_tmethodt
qualifierstQualifiers_tValuetNametjointgett
provenancetInParameterst
in_parameterst
OutParameterstout_parametersR;tin_parameter_namestProperties_tIsArraytout_parameter_namesR"t
pywintypesR:RY(	R
Rtmethod_nametqRdR5tis_arraytdoct
privileges((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRTs2	!..07
cOs"y|jr|i}x!|jD]\}}|||<qW|j}xxtt|��D]d}||}|j|}	|	jr�yt|�Wq�tk
r�td|��q�Xn||	_qRWx�|j	�D]�\}
}|j
|
�}|dkr
td|
|j
f��n;|rEyt|�WqEtk
rAtd|
��qEXn||j|
�_q�W|jj|jj|j�}n|jj|jj�}g}
xX|jD]M\}}|j|�j}|r�|
jt|p�g��q�|
j|�q�Wt|
�SWntjk
rt�nXdS(s�Execute the call to a WMI method, returning
    a tuple (even if is of only one value) containing
    the out and return parameters.
    sparameter %d must be iterables"%s is not a valid parameter for %ss%s must be iterableN(R�R�trangetlenR�R�RRR�RIR�R;R2R"RtExecMethod_R�R�R�RFttupleR�R:RY(R
RDtkwargstparameter_namesR5R�t
parameterstn_argtargt	parametertktvR6tresultsR4((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__call__xsH		

	


!cCsd|jS(Ns
<function %s>(R"(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s(R R!R"RR�R(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR|Hs
	$	9t
_wmi_propertycBs,eZd�Zd�Zd�Zd�ZRS(cCsY||_|j|_|j|_td�|jD��|_|jjdd�|_
dS(Ncss!|]}|j|jfVqdS(N(R�R�(t.0R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pys	<genexpr>�stCIMTYPE(tpropertyR�R5R�R4RR�R�R�R;ttype(R
R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s
	cCs||j_dS(N(R�R�(R
R4((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR#�scCsd|jS(Ns<wmi_property: %s>(R5(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�scCst|j|�S(N(RR�(R
tattr((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s(R R!RR#RR(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR��s			t_wmi_objectcBs�eZdZdgid�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zee�Zd
�Zd�Zd�Zd�Zd�Zd�Zee�Zddd�Zdd�ZRS(s�The heart of the WMI module: wraps the objects returned by COM
  ISWbemObject interface and provide readier access to their properties
  and methods resulting in a more Pythonic interface. Not usually
  instantiated directly, rather as a result of calling a :class:`_wmi_class`
  on the parent :class:`_wmi_namespace`.

  If you get hold of a WMI-related COM object from some other
  source than this module, you can wrap it in one of these objects
  to get the benefits of the module::

    import win32com.client
    import wmi

    wmiobj = win32com.client.GetObject ("winmgmts:Win32_LogicalDisk.DeviceID='C:'")
    c_drive = wmi._wmi_object (wmiobj)
    print c_drive
  cCsyyWt|d|�t|d|jjj��t|d|�t|di�t|di�t|d|�t|dd�t|dd�|r�xB|D]}d|j|<q�Wn$x!|jD]}d|j|j<q�Wx!|jD]}d|j	|j<q�Wt|d	|jj
��t|d
|j	j
��t|dtd�|jj
D���Wntjk
rtt�nXdS(
NRtidt_instance_oft
propertiestmethodstproperty_mapt_associated_classest_keyst_propertiest_methodsR�css!|]}|j|jfVqdS(N(R�R�(R�R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pys	<genexpr>�s(R{tPath_tDisplayNametlowerR;R�R�R�R�R�tkeysRRR�R�R:RY(R
Rtinstance_oftfieldsR�tfieldtptm((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s*
*cCs|j|jkS(N(R�(R
tother((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__lt__�scCs3y|jj�SWntjk
r.t�nXdS(siFor a call to print [object] return the OLE description
    of the properties / values of the object
    N(RtGetObjectText_R�R:RY(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�scCsLy*d|jj|jjjdd�fSWntjk
rGt�nXdS(sr
    Indicate both the fact that this is a wrapped WMI object
    and the WMI object's own identifying class.
    s<%s: %s>tasciitbackslashreplaceN(t	__class__R R�tPathtencodeR�R:RY(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRs*cCs@|j|dkr5t|jj|��|j|<n|j|S(N(R�R;R�RR�(R
R((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt_cached_propertiess"cCs:|j|dkr/t|j|�|j|<n|j|S(N(R�R;R|R(R
R((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt_cached_methodsscCs�y�||jkr�|j|�}|jj||jj|jd���}||j�}|jjd�rytd|�S|Sn,||jkr�|j	|�St
|j|�SWntj
k
r�t�nXdS(s.
    Attempt to pass attribute calls to the proxied COM object.
    If the attribute is recognised as a property, return its value;
    if it is recognised as a method, return a method wrapper which
    can then be called with parameters; otherwise pass the lookup
    on to the underlying object.
    cSs|S(N((tx((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt<lambda>#R8sref:tmonikerN(R�R�R�R�R�R4R0tWMIR�R�RRR�R:RY(R
RR�tfactoryR4((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRs*

cCsyyW||jkrJ|j|�j|�|jjjrV|jj�qVnt|��Wntj	k
rtt
�nXdS(s�If the attribute to be set is valid for the proxied
    COM object, set that objects's parameter value; if not,
    raise an exception.
    N(R�R�R#RR�R�tPut_R2R�R:RY(R
RR4((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__setattr__5scCs|j|jkS(N(R�(R
R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__eq__DscCs
t|j�S(N(thashR�(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt__hash__GscCs[g|jj�D]}t|�^q}|jg|jj�D]}t|�^q>�|S(s8Return list of methods/properties for IPython completion(R�R�RtextendR�(R
R�tattribs((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt_getAttributeNamesJs(/cCs�|jdkr{t|dg�xY|jjD]H}x?|jD]4}|jdkr<|jr<|jj|j�q<q<Wq,Wn|jS(s�A WMI object is uniquely defined by a set of properties
    which constitute its keys. Lazily retrieves the keys for this
    instance or class.

    :returns: list of key property names
    R�tkeyN(	R�R;R{RR�R�R�R�RF(R
R�t	qualifier((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt	_get_keysPs
!cCst|jj|��S(sJReturn the cached object representing one property
    of this object
    (R�RR�(R
t
property_name((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytwmi_propertycscCs|jj�dS(sHPush all outstanding property updates back to the
    WMI database.
    N(RR�(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytputiscKs�|r�ytxN|j�D]@\}}||jkrJ|j|�j|�qt|��qW|jjjry|jj�nWq�t	j
k
r�t�q�XndS(s)Set several properties of the underlying object
    at one go. This is particularly useful in combination
    with the new () method below. However, an instance
    which has been spawned in this way won't have enough
    information to write pack, so only try if the
    instance has a path.
    N(RIR�R�R#R2RR�R�R�R�R:RY(R
R�RR4((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR#oscCs0y|jjSWntjk
r+t�nXdS(s�Return the WMI URI to this object. Can be used to
    determine the path relative to the parent namespace::

      pp0 = wmi.WMI ().Win32_ParallelPort ()[0]
      print pp0.path ().RelPath

    ..  Do more with this
    N(RR�R�R:RY(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytpath�s	cCs0y|jjSWntjk
r+t�nXdS(s�Return a tuple representing the object derivation for
    this object, with the most specific object first::

      pp0 = wmi.WMI ().Win32_ParallelPort ()[0]
      print ' <- '.join (pp0.derivation ())
    N(RtDerivation_R�R:RY(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt
derivation�scs��jdkr�t�t�r.itd6}n
itd6}y<t�fd��jj|�D��}t�d|�Wq�t	j
k
r�t�q�Xn�jS(NtbSchemaOnlytbClassesOnlyc3s-|]#}|jjt�j|�fVqdS(N(R�tClasst
_wmi_classt
_namespace(R�tassoc(R
(sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pys	<genexpr>�sR�(R�R;t
isinstanceR�tTrueRRtAssociators_R{R�R:RY(R
tparamstassociated_classes((R
sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt_cached_associated_classes�s
R8cCsXy6g|jjd|d|�D]}t|�^qSWntjk
rSt�nXdS(s�Return a list of objects related to this one, optionally limited
    either by association class (ie the name of the class which relates
    them) or by result class (ie the name of the class which would be
    retrieved)::

      c = wmi.WMI ()
      pp = c.Win32_ParallelPort ()[0]

      for i in pp.associators (wmi_association_class="Win32_PortResource"):
        print i

      for i in pp.associators (wmi_result_class="Win32_PnPEntity"):
        print i
    t
strAssocClasststrResultClassN(RR�R�R�R:RY(R
twmi_association_classtwmi_result_classRd((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytassociators�s!cCsRy0g|jjd|�D]}t|�^qSWntjk
rMt�nXdS(s Return a list of associations involving this object, optionally
    limited by the result class (the name of the association class).

    NB Associations are treated specially; although WMI only returns
    the string corresponding to the instance of each associated object,
    this module will automatically convert that to the object itself::

      c =  wmi.WMI ()
      sp = c.Win32_SerialPort ()[0]

      for i in sp.references ():
        print i

      for i in sp.references (wmi_class="Win32_SerialPortSetting"):
        print i
    R�N(RtReferences_R�R�R:RY(R
t	wmi_classRd((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt
references�s0N(R R!R"R;RR�RRR�R�RR�R�R�R�R�R�R�R�R�R#R�R�R�R�R�R�(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR��s.				
														t
_wmi_eventcBs)eZdZejd�Zgd�ZRS(s�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.
  s/__Instance(Creation|Modification|Deletion)EventcCs�tj||d|�t|dd�t|dd�t|dd�|r�|jj|jj�jd�j	�}t|d|�t
|d�r�t|dt|j��nt
|d�r�t|d|j
�q�ndS(NR�t
event_typet	timestamptpreviousitTIME_CREATEDtPreviousInstance(R�RR{R;t
event_type_retmatchR�R�tgroupR�thasattrR`R�R�(R
teventt
event_infoR�R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s'(R R!R"tretcompileR�R(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR��sR�cBsVeZdZd�Zd�Zgd�ZeZddgd�Zd�Zd�Z	RS(	s�Currying class to assist in issuing queries against
   a WMI namespace. The idea is that when someone issues
   an otherwise unknown method against the WMI object, if
   it matches a known WMI class a query object will be
   returned which may then be called with one or more params
   which will form the WHERE clause::

    c = wmi.WMI ()
    c_drives = c.Win32_LogicalDisk (Name='C:')
  cCs�tj||�t|d|jj�|r?t|d|�nQ|jj}|jd�\}}}tt|d|�t	�}t|d|�dS(Nt_class_nameR�t:(
R�RR{R�R�R�tsplitt_wmi_namespaceRtFalse(R
t	namespaceR�t
class_monikertwinmgmtstnamespace_monikert
class_name((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRscCsXy6||jkr%t|j|��Stj||�SWntjk
rSt�nXdS(N(R�R�R�R�RR�R:RY(R
R((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRsc	Ks�|jd	krtd��ny�dj|�p3d}d|d|j}|r�|ddjg|j�D]"\}}d|t|�f^qj�7}n|jj|||�SWntj	k
r�t
�nXd	S(
s�Make it slightly easier to query against the class,
     by calling the namespace's query with the class preset.
     Won't work if the class has been instantiated directly.
    s*You cannot query directly from a WMI classs, RasSELECT s FROM s WHERE s AND s%s = %rN(R�R;R>R�RRIRtqueryR�R:RY(R
R�twhere_clauset
field_listtwqlR�R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR
!sIt	operationic
Ksz|jdkrtd��nd}|j�|krRtddj|���n|jjd|d	|d
|d||�S(
Ns*You cannot watch directly from a WMI classRtcreationtdeletiontmodifications#notification_type must be one of %ss, tnotification_typeR�t
delay_secsR�(RRRR(R�R;R>R�R7R�t	watch_for(R
RRR�Rtvalid_notification_types((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR7scCsLy*g|j�D]}t||�^qSWntjk
rGt�nXdS(s0Return a list of instances of the WMI class
    N(t
Instances_R�R�R:RY(R
tinstance((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt	instancesMs*cKsLy*t|j�|�}|j|�|SWntjk
rGt�nXdS(s�This is the equivalent to the raw-WMI SpawnInstance\_
    method. Note that there are relatively few uses for
    this, certainly fewer than you might imagine. Most
    classes which need to create a new *real* instance
    of themselves, eg Win32_Process, offer a .Create
    method. SpawnInstance\_ is generally reserved for
    instances which are passed as parameters to such
    `.Create` methods, a common example being the
    `Win32_SecurityDescriptor`, passed to `Win32_Share.Create`
    and other instances which need security.

    The example here is `Win32_ProcessStartup`, which
    controls the shown/hidden state etc. of a new
    `Win32_Process` instance::

      import win32con
      import wmi
      c = wmi.WMI ()
      startup = c.Win32_ProcessStartup.new (ShowWindow=win32con.SW_SHOWMINIMIZED)
      pid, retval = c.Win32_Process.Create (
        CommandLine="notepad.exe",
        ProcessStartupInformation=startup
      )

    ..  warning::
        previous versions of this docstring illustrated using this function
        to create a new process. This is *not* a good example of its use;
        it is better handled with something like the example above.
    N(R�tSpawnInstance_R#R�R:RY(R
R�Rz((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytnewUs
(
R R!R"RRR
R�RRR(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s
		
	t_wmi_resultcBseZdZd�ZRS(ssSimple, data only result for targeted WMI queries which request
  data only result classes via fetch_as_classes.
  cCsm|r3x`|D]}|j|�j|j|<q
Wn6x3|jD](}|j}|j|�j|j|<q=WdS(N(R�R�R(R�(R
Rzt
attributesR�R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s
 	(R R!R"R(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR}sRcBs�eZdZd�Zd�Zd�Zd�Zee�Zd�Z	d�Z
ddd	�Zd
�Zd�Z
e
Zd�Zdgd
�Zdd�Zd�Zddddgd�Zd�Zd�Zd�ZRS(s�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::

    c = wmi.WMI ()
    for i in c.classes:
      if "user" in i.lower ():
        print i
  cCsHt|d|�t|d|�d|_i|_|rD|j}ndS(NR�twmi(R{R;t_classest_classes_maptclasses(R
Rtfind_classesRK((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s			cCsd|jS(Ns<_wmi_namespace: %s>(R(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�scCs
t|�S(N(R(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�scCs7|jdkr!|j�|_nttj|j��S(N(RR;t
subclasses_ofR
Rtfromkeys(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt_get_classes�scCs<yt|jj|��SWntjk
r7t�nXdS(N(R�RtGetR�R:RY(R
R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR��scCs|jS(s1The raw OLE object representing the WMI namespace(R�(R
((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pythandle�sR8s.*csLy|jj}Wntk
r't�SXt�fd�||�D��SdS(Nc3s3|])}tj�|jj�r|jjVqdS(N(R�R�R�R�(R�tc(tregex(sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pys	<genexpr>�s(R�tSubclassesOfR2R#(R
trootR(R)((R(sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR"�s
cCsOy-g|jj|�D]}t|�^qSWntjk
rJt�nXdS(s�Return a list of instances of the WMI class. This is
    (probably) equivalent to querying with no qualifiers::

      wmi.WMI ().instances ("Win32_LogicalDisk")
      # should be the same as
      wmi.WMI ().Win32_LogicalDisk ()
    N(R�tInstancesOfR�R�R:RY(R
R	Rz((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s-cKst||�j|�S(s;This is now implemented by a call to :meth:`_wmi_class.new`(RR(R
R�R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�scCs[ttB}|jdd�}y|jjd|d|�SWntjk
rVt�nXdS(s�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.
    NB Backslashes need to be doubled up.
    s\s\\tstrQuerytiFlagsN(twbemFlagReturnImmediatelytwbemFlagForwardOnlytreplaceR�t	ExecQueryR�R:RY(R
R
tflags((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt
_raw_query�s
cCs,g|j|�D]}t|||�^qS(szPerform an arbitrary query against a WMI object, and return
    a list of _wmi_object representations of the results.
    (R3R�(R
R
R�R�Rz((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR
�scKs�d|rdj|�pd|f}|rn|ddjg|j�D]\}}d||f^qD�7}ng|j|�D]}t||�^q~S(sHBuild 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 field_list.

    If fields is left empty, select * and pre-load all class attributes for
    each class returned.
    sSELECT %s FROM %ss, Ras WHERE s AND s	%s = '%s'(R�RIR3R(R
t
wmi_classnameR�RR
R�R�Rz((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytfetch_as_classes�s%Cc
Ks�ddj|�|f}|rb|ddjg|j�D]\}}d||f^q8�7}ng}xC|j|�D]2}|jg|D]}	|j|	�j^q��qxW|S(s�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 to field_list.
    sSELECT %s FROM %ss, s WHERE s AND s	%s = '%s'(R�RIR3RFR�R�(
R
R4R�RR
R�R�R�RzR�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytfetch_as_listssC0RicKs�t|t�r|j}n|}t||�}d|j�k}|rQ|}	n�tdg|pfdg�}dj|�}
|r�|r�ddjg|j�D]\}}d||f^q��}
nd}
d	|
d
||
}	nd|r+ddjg|j�D]\}}d||f^q�}
nd}
d|
||||
f}	y&t|j	j
|	�d
|d|�SWntjk
r�t
�nXdS(sVSet up an event tracker on a WMI event. This function
    returns an wmi_watcher which can be called to get the
    next event::

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

    Now supports timeout on the call to watcher::

      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
    t__ExtrinsicEventtTargetInstanceRas, s WHERE s AND s	%s = '%s'R8sSELECT s FROM sTargetInstance.%s = '%s'sKSELECT %s FROM __Instance%sEvent WITHIN %d WHERE TargetInstance ISA '%s' %stis_extrinsicR�N(R�R�RRR�R#R�RIt_wmi_watcherR�tExecNotificationQueryR�R:RY(R
traw_wqlRR�RR�RR	R9R
RR�R�twhere((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR
s4>	??cCs9y|j|�SWn!tjk
r4t|j|�SXdS(s�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.
    N(t_cached_classesR�R:RR�(R
R((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRns
cCs?||jkr4t||jj|��|j|<n|j|S(s�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
    (RR�R�R%(R
R	((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR>}s%cCs)g|jD]}|jd�s
|^q
S(s4Return list of classes for IPython completion engineR/(R R0(R
R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR��sN((R R!R"RRRR$R�R R�R&R"RRtnew_instance_ofR3R;R
R5R6RRR>R�(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s0								
		

	[		
R:cBs:eZdZied6ed6Zgd�Zdd�ZRS(s)Helper class for WMI.watch_for below (qv)R8R�cCs||_||_||_dS(N(t	wmi_eventR9R�(R
R@R9R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR�s		i����cCs�y`|jj|�}|jr1t|d|j�St|jd�jt|d|j	�|j�SWnt
jk
r}t�nXdS(sWhen called, return the instance which caused the event. Supports
     timeout in milliseconds (defaulting to infinite). If the watcher
     times out, :exc:`x_wmi_timed_out` is raised. This makes it easy to support
     watching for multiple objects.
    R8R�N(
R@t	NextEventR9R�R;R�R�R�R�t_event_property_mapR�R:RY(R
t
timeout_msR�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR��s	(R R!R"R�RBRR�(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyR:�s
R8c
Cs�|aywyU|r|}
n�|rL|jt�s=t|}nt|�}
n�|	r�|s^|rmtd��q�|dkr�td��q�td|d|d|	d|
d	|d
|d|�}
n?td|d
|d|d	|d
|d|d|�}t|�}
t|
�}|dkr"t	|
|�S|dkr;t
d|
�S|dkrQt|
�Std��Wnt
jk
r{t�nXWntk
r�td��nXdS(s�The WMI constructor can either take a ready-made moniker or as many
  parts of one as are necessary. Eg::

    c = wmi.WMI (moniker="winmgmts:{impersonationLevel=Delegate}//remote")
    # or
    c = wmi.WMI (computer="remote", privileges=["!RemoteShutdown", "Security"])

  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::

    loc = win32com.client.Dispatch("WbemScripting.SWbemLocator")
    svc = loc.ConnectServer(...)
    c = wmi.WMI(wmi=svc)

  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.
  s>You can't specify privileges or a suffix as well as a usernameR8Rgs:You can only specify user/password for a remote connectiontserverRtusertpasswordt	authoritytimpersonation_leveltauthentication_leveltcomputerR�tsuffixtclassRsUnknown moniker typesuWMI returned a syntax error: you're probably running inside a thread without first calling pythoncom.CoInitialize[Ex]N(NR8Rg(t_DEBUGR0tPROTOCOLRR@R;tconnect_servertconstruct_monikertget_wmi_typeRR�R�R7R�R:RYRA(RJRHRIRGR�R�RRRKRERFR!tdebugRztwmi_type((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytconnect�sV'	
	



c
Cs>g}|r |jd|�n|r:|jd|�n|rZ|rZ|jd|�n|r}|jddj|��ntg}|r�|jddj|��n|r�|jd|�n|rtjd	|�}	|	d
dkr�|	jd
d�n|jdj|	��n|r1|jd
|�ndj|�S(NsimpersonationLevel=%ssauthenticationLevel=%ssauthority=%ss(%s)s, s{%s}!t,s//%s/s[/\\]iR*t/s:%sR8(RFR�RNR�Rtinsert(
RJRHRIRGR�RRKtsecurityR�tparts((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRPs,		cCs7y
|j}Wntk
r!dSX|jr/dSdSdS(NRRLR(R�R2tIsClass(RzR�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRQ.s

	i�c
	Cs�|rMy ttjd|j��}
WqStk
rItd|��qSXnd}
|r�y ttjd|j��}Wq�tk
r�td|��q�Xnd}td�j||||||||	�}|
r�|
|j	_
n|r�||j	_n|S(s{Return a remote server running WMI

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

  Example::

    remote_connetion = wmi.connect_server (
      server="remote_machine", user="myname", password="mypassword"
    )
    c = wmi.WMI (wmi=remote_connection)
  swbemImpersonationLevel%ssNo such impersonation level: %sswbemAuthenticationLevel%ssWbemScripting.SWbemLocatorN(RRzR'ttitleR2R@R;Rt
ConnectServert	Security_tImpersonationLeveltAuthenticationLevel(RDRRERFtlocaleRGRHRItsecurity_flagstnamed_value_sett
impersonationtauthentication((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyRO9s4# 
 
	tImpersonatetDefaultcCs�tjdt�|sLtd|d|d|d|d|ddd	d
�}nytt|��SWntjk
r}t�nXdS(NsOThis function can be implemented using wmi.WMI (namespace='DEFAULT').StdRegProvRJRHRIRGR�RtdefaultRKt
StdRegProv(	RRRRPR�RR�R:RY(RJRHRIRGR�R�((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pytRegistry}s	t__main__sDisks on(AR"t__VERSION__t__version__RRMRBR\R�RRtwin32com.clientRRR�R	tobjectR
R&RzR'twbemErrInvalidQuerytwbemErrTimedoutR.R/t	ExceptionR7R<R=R>R?R@RARHR;RYR[R`RsRyR{R|R�R�R�R�RRR:RNRTR�RPRQRORiR tsystemtWin32_ComputerSystemtmy_computerR�tWin32_LogicalDisktdisktCaptiontDescriptiontProviderName(((sDC:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party\wmi.pyt<module>Ms�
	
%



	!)		
l�"|�T	
;	

© 2026 UnknownSec