Beispiel #1
0
    def set_default(self):

        self.__device_enum = comtypes.CoCreateInstance(
            CLSID_MMDeviceEnumerator, IMMDeviceEnumerator,
            comtypes.CLSCTX_INPROC_SERVER)

        policy_config = comtypes.CoCreateInstance(
            CLSID_PolicyConfigVistaClient, IPolicyConfigVista,
            comtypes.CLSCTX_ALL)

        policy_config.SetDefaultEndpoint(self.id, ERole.eMultimedia)
Beispiel #2
0
    def __init__(self):
        self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
        self.ui_automation_client = comtypes.gen.UIAutomationClient
        self.iuia = comtypes.CoCreateInstance(
                self.ui_automation_client.CUIAutomation().IPersist_GetClassID(),
                interface=self.ui_automation_client.IUIAutomation,
                clsctx=comtypes.CLSCTX_INPROC_SERVER
                )
        self.true_condition = self.iuia.CreateTrueCondition()
        self.tree_scope = {
                'ancestors': self.UIA_dll.TreeScope_Ancestors,
                'children': self.UIA_dll.TreeScope_Children,
                'descendants': self.UIA_dll.TreeScope_Descendants,
                'element': self.UIA_dll.TreeScope_Element,
                'parent': self.UIA_dll.TreeScope_Parent,
                'subtree': self.UIA_dll.TreeScope_Subtree,
                }
        self.root = self.iuia.GetRootElement()

        self.get_focused_element = self.iuia.GetFocusedElement

        # collect all known control types
        start_len = len('UIA_')
        end_len = len('ControlTypeId')
        self._control_types = [attr[start_len:-end_len] for attr in dir(self.UIA_dll) if attr.endswith('ControlTypeId')]

        self.known_control_types = { 'InvalidControlType': 0 } # string id: numeric id
        self.known_control_type_ids = { 0: 'InvalidControlType' } # numeric id: string id

        for ctrl_type in self._control_types:
            type_id_name = 'UIA_' + ctrl_type + 'ControlTypeId'
            type_id = getattr(self.UIA_dll, type_id_name)
            self.known_control_types[ctrl_type] = type_id
            self.known_control_type_ids[type_id] = ctrl_type
Beispiel #3
0
def CreateObject(progid,                  # which object to create
                 clsctx=None,             # how to create the object
                 machine=None,            # where to create the object
                 interface=None):         # the interface we want
    """Create a COM object from 'progid', and try to QueryInterface()
    it to the most useful interface, generating typelib support on
    demand.  A pointer to this interface is returned.

    'progid' may be a string like "InternetExplorer.Application",
       a string specifying a clsid, a GUID instance, or an object with
       a _clsid_ attribute which should be any of the above.
    'clsctx' specifies how to create the object, use the CLSCTX_... constants.
    'machine' allows to specify a remote machine to create the object on.

    You can also later request to receive events with GetEvents().
    """
    clsid = comtypes.GUID.from_progid(progid)
    logger.debug("%s -> %s", progid, clsid)
    if interface is None:
        interface = getattr(progid, "_com_interfaces_", [None])[0]
    if machine is None:
        logger.debug("CoCreateInstance(%s, clsctx=%s, interface=%s)",
                     clsid, clsctx, interface)
        obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
    else:
        logger.debug("CoCreateInstanceEx(%s, clsctx=%s, interface=%s, machine=%s)",
                     clsid, clsctx, interface, machine)
        obj = comtypes.CoCreateInstanceEx(clsid, clsctx=clsctx, interface=interface, machine=machine)
    return _manage(obj, clsid, interface=interface)
Beispiel #4
0
 def __init__(self):
     print('Initializing UIA COM')
     comtypes.client.GetModule('UIAutomationCore.dll')
     # noinspection PyProtectedMember,PyUnresolvedReferences
     self.uia = comtypes.CoCreateInstance(
         comtypes.gen.UIAutomationClient.CUIAutomation._reg_clsid_,
         interface=comtypes.gen.UIAutomationClient.IUIAutomation,
         clsctx=comtypes.CLSCTX_INPROC_SERVER)
def _get_default_endpoint_volume():
    enumerator = comtypes.CoCreateInstance(
                    CLSID_MMDeviceEnumerator,
                    IMMDeviceEnumerator,
                    comtypes.CLSCTX_INPROC_SERVER)
    endpoint = enumerator.GetDefaultAudioEndpoint(0, 1)
    return endpoint.Activate(IID_IAudioEndpointVolume,
                             comtypes.CLSCTX_INPROC_SERVER,
                             None)
Beispiel #6
0
    def GetSpeakers():
        """
				get the speakers (1st render + multimedia) device
				"""
        deviceEnumerator = comtypes.CoCreateInstance(
            CLSID_MMDeviceEnumerator, IMMDeviceEnumerator,
            comtypes.CLSCTX_INPROC_SERVER)
        speakers = deviceEnumerator.GetDefaultAudioEndpoint(
            EDataFlow.eRender.value, ERole.eMultimedia.value)
        return speakers
Beispiel #7
0
    def GetDefaultMicrophone():
        deviceEnumerator = comtypes.CoCreateInstance(
            CLSID_MMDeviceEnumerator, IMMDeviceEnumerator,
            comtypes.CLSCTX_INPROC_SERVER)
        microphone = deviceEnumerator.GetDefaultAudioEndpoint(
            EDataFlow.eCapture.value, ERole.eMultimedia.value)
        o = microphone.Activate(IAudioEndpointVolume._iid_,
                                comtypes.CLSCTX_ALL, None)
        microphone = o.QueryInterface(IAudioEndpointVolume)

        return microphone
Beispiel #8
0
def CreateObject(
    progid,  # which object to create
    clsctx=None,  # how to create the object
    machine=None,  # where to create the object
    interface=None,  # the interface we want
    dynamic=False,  # use dynamic dispatch
    pServerInfo=None):  # server info struct for remoting
    """Create a COM object from 'progid', and try to QueryInterface()
    it to the most useful interface, generating typelib support on
    demand.  A pointer to this interface is returned.

    'progid' may be a string like "InternetExplorer.Application",
       a string specifying a clsid, a GUID instance, or an object with
       a _clsid_ attribute which should be any of the above.
    'clsctx' specifies how to create the object, use the CLSCTX_... constants.
    'machine' allows to specify a remote machine to create the object on.
    'interface' allows to force a certain interface
    'dynamic=True' will return a dynamic dispatch object
    'pServerInfo', if used, must be a pointer to a comtypes.COSERVERINFO instance
        This supercedes 'machine'.

    You can also later request to receive events with GetEvents().
    """
    clsid = comtypes.GUID.from_progid(progid)
    logger.debug("%s -> %s", progid, clsid)
    if dynamic:
        if interface:
            raise ValueError("interface and dynamic are mutually exclusive")
        interface = comtypes.automation.IDispatch
    elif interface is None:
        interface = getattr(progid, "_com_interfaces_", [None])[0]
    if machine is None and pServerInfo is None:
        logger.debug("CoCreateInstance(%s, clsctx=%s, interface=%s)", clsid,
                     clsctx, interface)
        obj = comtypes.CoCreateInstance(clsid,
                                        clsctx=clsctx,
                                        interface=interface)
    else:
        logger.debug(
            "CoCreateInstanceEx(%s, clsctx=%s, interface=%s, machine=%s,\
                        pServerInfo=%s)", clsid, clsctx, interface, machine,
            pServerInfo)
        if machine is not None and pServerInfo is not None:
            msg = "You can notset both the machine name and server info."
            raise ValueError(msg)
        obj = comtypes.CoCreateInstanceEx(clsid,
                                          clsctx=clsctx,
                                          interface=interface,
                                          machine=machine,
                                          pServerInfo=pServerInfo)
    if dynamic:
        return comtypes.client.dynamic.Dispatch(obj)
    return _manage(obj, clsid, interface=interface)
    def GetAllDevices():
        devices = []
        deviceEnumerator = comtypes.CoCreateInstance(
            CLSID_MMDeviceEnumerator, IMMDeviceEnumerator,
            comtypes.CLSCTX_INPROC_SERVER)
        if deviceEnumerator is None:
            return devices

        collection = deviceEnumerator.EnumAudioEndpoints(
            EDataFlow.eAll.value, DEVICE_STATE.MASK_ALL.value)
        if collection is None:
            return devices

        count = collection.GetCount()
        for i in range(count):
            dev = collection.Item(i)
            if dev is not None:
                devices.append(AudioUtilities.CreateDevice(dev))
        return devices
Beispiel #10
0
 def get_default(cls, dataFlow, role):
     enumerator = comtypes.CoCreateInstance(CLSID_MMDeviceEnumerator, cls,
                                            comtypes.CLSCTX_INPROC_SERVER)
     return enumerator.GetDefaultAudioEndpoint(dataFlow, role)
Beispiel #11
0
 def __init__(self):
     self.__device_enum = comtypes.CoCreateInstance(
         CLSID_MMDeviceEnumerator,
         IMMDeviceEnumerator,
         comtypes.CLSCTX_INPROC_SERVER
     )
from collections import deque
from xml.dom import minidom

import comtypes
import comtypes.client

__version__ = '1.0.0'

UIAutomationClient = comtypes.client.GetModule('UIAutomationCore.dll')

# noinspection PyProtectedMember
_IUIAutomation = comtypes.CoCreateInstance(UIAutomationClient.CUIAutomation._reg_clsid_,
                                           interface=UIAutomationClient.IUIAutomation,
                                           clsctx=comtypes.CLSCTX_INPROC_SERVER)

_control_type = {
    UIAutomationClient.UIA_ButtonControlTypeId: 'UIA_ButtonControlTypeId',
    UIAutomationClient.UIA_CalendarControlTypeId: 'UIA_CalendarControlTypeId',
    UIAutomationClient.UIA_CheckBoxControlTypeId: 'UIA_CheckBoxControlTypeId',
    UIAutomationClient.UIA_ComboBoxControlTypeId: 'UIA_ComboBoxControlTypeId',
    UIAutomationClient.UIA_CustomControlTypeId: 'UIA_CustomControlTypeId',
    UIAutomationClient.UIA_DataGridControlTypeId: 'UIA_DataGridControlTypeId',
    UIAutomationClient.UIA_DataItemControlTypeId: 'UIA_DataItemControlTypeId',
    UIAutomationClient.UIA_DocumentControlTypeId: 'UIA_DocumentControlTypeId',
    UIAutomationClient.UIA_EditControlTypeId: 'UIA_EditControlTypeId',
    UIAutomationClient.UIA_GroupControlTypeId: 'UIA_GroupControlTypeId',
    UIAutomationClient.UIA_HeaderControlTypeId: 'UIA_HeaderControlTypeId',
    UIAutomationClient.UIA_HeaderItemControlTypeId: 'UIA_HeaderItemControlTypeId',
    UIAutomationClient.UIA_HyperlinkControlTypeId: 'UIA_HyperlinkControlTypeId',
    UIAutomationClient.UIA_ImageControlTypeId: 'UIA_ImageControlTypeId',
    UIAutomationClient.UIA_ListControlTypeId: 'UIA_ListControlTypeId',
            (['out'], POINTER(DWORD), 'pdwCookie'),
        ),
        COMMETHOD(
            [helpstring('Method Unregister')],
            HRESULT,
            'Unregister',
            (['in'], DWORD, 'dwCookie'),
        ),
    ]


comtypes.CoInitialize()

pServiceProvider = comtypes.CoCreateInstance(
    CLSID_ImmersiveShell,
    IServiceProvider,
    comtypes.CLSCTX_LOCAL_SERVER,
)

pDesktopManagerInternal = comtypes.cast(
    pServiceProvider.QueryService(CLSID_VirtualDesktopManagerInternal,
                                  IID_IVirtualDesktopManagerInternal),
    ctypes.POINTER(IVirtualDesktopManagerInternal))

pObjectArray = POINTER(IObjectArray)()

pDesktopManagerInternal.GetDesktops(ctypes.byref(pObjectArray))

count = UINT()
pObjectArray.GetCount(ctypes.byref(count))
Beispiel #14
0
 def SetDefaultEndpoint(deviceName, eRole):
     policy = comtypes.CoCreateInstance(POLICY_CONFIG_CLIENT_IID, IPolicyConfigX, comtypes.CLSCTX_INPROC_SERVER)