Python pythoncom 模块,CLSCTX_INPROC_SERVER 实例源码

我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用pythoncom.CLSCTX_INPROC_SERVER

项目:code    作者:ActiveState    | 项目源码 | 文件源码
def resolve_shortcut(filename):
    """resolve_shortcut("Notepad.lnk") => "C:\WINDOWS\system32\notepad.exe"

    Returns the path refered to by a windows shortcut (.lnk) file.
    """

    shell_link = pythoncom.CoCreateInstance(
        shell.CLSID_ShellLink, None,
        pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)

    persistant_file = shell_link.QueryInterface(pythoncom.IID_IPersistFile)

    persistant_file.Load(filename)

    shell_link.Resolve(0, 0)
    linked_to_file = shell_link.GetPath(shell.SLGP_UNCPRIORITY)[0]
    return linked_to_file
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def __init__(self, 
                 path=None,
                 arguments=None, 
                 description=None,
                 workingdir=None,
                 iconpath=None,
                 iconidx=0):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
        data = map(None, 
                   ['"%s"' % os.path.abspath(path), arguments, description,
                    os.path.abspath(workingdir), os.path.abspath(iconpath)], 
                   ("SetPath", "SetArguments", "SetDescription",
                   "SetWorkingDirectory") )
        for value, function in data:
            if value and function:
                # call function on each non-null value
                getattr(self, function)(value)
        if iconpath:
            self.SetIconLocation(iconpath, iconidx)
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def test(serverName):
    if string.lower(serverName)==string.lower(win32api.GetComputerName()):
        print "You must specify a remote server name, not the local machine!"
        return

    # Hack to overcome a DCOM limitation.  As the Python.Interpreter object
    # is probably installed locally as an InProc object, DCOM seems to ignore
    # all settings, and use the local object.
    clsctx = pythoncom.CLSCTX_SERVER & ~pythoncom.CLSCTX_INPROC_SERVER
    ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx)
    ob.Exec("import win32api")
    actualName = ob.Eval("win32api.GetComputerName()")
    if string.lower(serverName) != string.lower(actualName):
        print "Error: The object created on server '%s' reported its name as '%s'" % (serverName, actualName)
    else:
        print "Object created and tested OK on server '%s'" % serverName
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def testShellLink(self):
        desktop = str(shell.SHGetSpecialFolderPath(0, CSIDL_DESKTOP))
        num = 0
        shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
        persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
        names = [os.path.join(desktop, n) for n in os.listdir(desktop)]
        programs = str(shell.SHGetSpecialFolderPath(0, CSIDL_PROGRAMS))
        names.extend([os.path.join(programs, n) for n in os.listdir(programs)])
        for name in names:
            try:
                persistFile.Load(name,STGM_READ)
            except pythoncom.com_error:
                continue
            # Resolve is slow - avoid it for our tests.
            #shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
            fname, findData = shellLink.GetPath(0)
            unc = shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
            num += 1
        if num == 0:
            # This isn't a fatal error, but is unlikely.
            print "Could not find any links on your desktop or programs dir, which is unusual"
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def test(serverName):
    if string.lower(serverName)==string.lower(win32api.GetComputerName()):
        print "You must specify a remote server name, not the local machine!"
        return

    # Hack to overcome a DCOM limitation.  As the Python.Interpreter object
    # is probably installed locally as an InProc object, DCOM seems to ignore
    # all settings, and use the local object.
    clsctx = pythoncom.CLSCTX_SERVER & ~pythoncom.CLSCTX_INPROC_SERVER
    ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx)
    ob.Exec("import win32api")
    actualName = ob.Eval("win32api.GetComputerName()")
    if string.lower(serverName) != string.lower(actualName):
        print "Error: The object created on server '%s' reported its name as '%s'" % (serverName, actualName)
    else:
        print "Object created and tested OK on server '%s'" % serverName
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def testShellLink(self):
        desktop = str(shell.SHGetSpecialFolderPath(0, CSIDL_DESKTOP))
        num = 0
        shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
        persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
        names = [os.path.join(desktop, n) for n in os.listdir(desktop)]
        programs = str(shell.SHGetSpecialFolderPath(0, CSIDL_PROGRAMS))
        names.extend([os.path.join(programs, n) for n in os.listdir(programs)])
        for name in names:
            try:
                persistFile.Load(name,STGM_READ)
            except pythoncom.com_error:
                continue
            # Resolve is slow - avoid it for our tests.
            #shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
            fname, findData = shellLink.GetPath(0)
            unc = shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
            num += 1
        if num == 0:
            # This isn't a fatal error, but is unlikely.
            print "Could not find any links on your desktop or programs dir, which is unusual"
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def __init__(self, 
                 path=None,
                 arguments=None, 
                 description=None,
                 workingdir=None,
                 iconpath=None,
                 iconidx=0):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
        data = map(None, 
                   ['"%s"' % os.path.abspath(path), arguments, description,
                    os.path.abspath(workingdir), os.path.abspath(iconpath)], 
                   ("SetPath", "SetArguments", "SetDescription",
                   "SetWorkingDirectory") )
        for value, function in data:
            if value and function:
                # call function on each non-null value
                getattr(self, function)(value)
        if iconpath:
            self.SetIconLocation(iconpath, iconidx)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def create_shortcut(path, description, filename,
                        arguments="", workdir="", iconpath="", iconindex=0):
        import pythoncom
        from win32com.shell import shell, shellcon

        ilink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None,
                                           pythoncom.CLSCTX_INPROC_SERVER,
                                           shell.IID_IShellLink)
        ilink.SetPath(path)
        ilink.SetDescription(description)
        if arguments:
            ilink.SetArguments(arguments)
        if workdir:
            ilink.SetWorkingDirectory(workdir)
        if iconpath or iconindex:
            ilink.SetIconLocation(iconpath, iconindex)
        # now save it.
        ipf = ilink.QueryInterface(pythoncom.IID_IPersistFile)
        ipf.Save(filename, 0)

    # Support the same list of "path names" as bdist_wininst.
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def test(serverName):
    if string.lower(serverName)==string.lower(win32api.GetComputerName()):
        print "You must specify a remote server name, not the local machine!"
        return

    # Hack to overcome a DCOM limitation.  As the Python.Interpreter object
    # is probably installed locally as an InProc object, DCOM seems to ignore
    # all settings, and use the local object.
    clsctx = pythoncom.CLSCTX_SERVER & ~pythoncom.CLSCTX_INPROC_SERVER
    ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx)
    ob.Exec("import win32api")
    actualName = ob.Eval("win32api.GetComputerName()")
    if string.lower(serverName) != string.lower(actualName):
        print "Error: The object created on server '%s' reported its name as '%s'" % (serverName, actualName)
    else:
        print "Object created and tested OK on server '%s'" % serverName
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def testShellLink(self):
        desktop = str(shell.SHGetSpecialFolderPath(0, CSIDL_DESKTOP))
        num = 0
        shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
        persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
        names = [os.path.join(desktop, n) for n in os.listdir(desktop)]
        programs = str(shell.SHGetSpecialFolderPath(0, CSIDL_PROGRAMS))
        names.extend([os.path.join(programs, n) for n in os.listdir(programs)])
        for name in names:
            try:
                persistFile.Load(name,STGM_READ)
            except pythoncom.com_error:
                continue
            # Resolve is slow - avoid it for our tests.
            #shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
            fname, findData = shellLink.GetPath(0)
            unc = shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
            num += 1
        if num == 0:
            # This isn't a fatal error, but is unlikely.
            print "Could not find any links on your desktop or programs dir, which is unusual"
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def test(serverName):
    if string.lower(serverName)==string.lower(win32api.GetComputerName()):
        print("You must specify a remote server name, not the local machine!")
        return

    # Hack to overcome a DCOM limitation.  As the Python.Interpreter object
    # is probably installed locally as an InProc object, DCOM seems to ignore
    # all settings, and use the local object.
    clsctx = pythoncom.CLSCTX_SERVER & ~pythoncom.CLSCTX_INPROC_SERVER
    ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx)
    ob.Exec("import win32api")
    actualName = ob.Eval("win32api.GetComputerName()")
    if string.lower(serverName) != string.lower(actualName):
        print("Error: The object created on server '%s' reported its name as '%s'" % (serverName, actualName))
    else:
        print("Object created and tested OK on server '%s'" % serverName)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def testShellLink(self):
        desktop = str(shell.SHGetSpecialFolderPath(0, CSIDL_DESKTOP))
        num = 0
        shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
        persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
        names = [os.path.join(desktop, n) for n in os.listdir(desktop)]
        programs = str(shell.SHGetSpecialFolderPath(0, CSIDL_PROGRAMS))
        names.extend([os.path.join(programs, n) for n in os.listdir(programs)])
        for name in names:
            try:
                persistFile.Load(name,STGM_READ)
            except pythoncom.com_error:
                continue
            # Resolve is slow - avoid it for our tests.
            #shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
            fname, findData = shellLink.GetPath(0)
            unc = shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
            num += 1
        if num == 0:
            # This isn't a fatal error, but is unlikely.
            print("Could not find any links on your desktop or programs dir, which is unusual")
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def __init__(self, 
                 path=None,
                 arguments=None, 
                 description=None,
                 workingdir=None,
                 iconpath=None,
                 iconidx=0):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
        data = map(None, 
                   ['"%s"' % os.path.abspath(path), arguments, description,
                    os.path.abspath(workingdir), os.path.abspath(iconpath)], 
                   ("SetPath", "SetArguments", "SetDescription",
                   "SetWorkingDirectory") )
        for value, function in data:
            if value and function:
                # call function on each non-null value
                getattr(self, function)(value)
        if iconpath:
            self.SetIconLocation(iconpath, iconidx)
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def read_scexec(scfile):
    """ read shortcut and return executable path """
    if sys.platform != 'win32':
        return "Only available for windows platforms! returning"
    try:
        import pythoncom
        from win32com.shell import shell, shellcon
    except:
        return "pythoncom module not found! \n download from http://sourceforge.net/projects/pywin32/files/pywin32/"
    shortcut = pythoncom.CoCreateInstance (
      shell.CLSID_ShellLink,
      None,
      pythoncom.CLSCTX_INPROC_SERVER,
      shell.IID_IShellLink
    )
    shortcut.QueryInterface (pythoncom.IID_IPersistFile).Load (scfile, 0)
    cmd, _ = shortcut.GetPath (shell.SLGP_UNCPRIORITY)
    args = shortcut.GetArguments ()
    work_dir = shortcut.GetWorkingDirectory()    
    return "Executing " + cmd, cmd, args, work_dir, False, False
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
def DumpLink(fname):
    shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
    persistFile.Load(fname,STGM_READ)
    shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
    fname, findData = shellLink.GetPath(0)
    print "Filename:", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
    print "Description:", shellLink.GetDescription()
    print "Working Directory:", shellLink.GetWorkingDirectory()
    print "Icon:", shellLink.GetIconLocation()
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_InternetShortcut, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IUniformResourceLocator
        )
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
def set_shortcut():
    startup_path = shell.SHGetPathFromIDList(shell.SHGetSpecialFolderLocation(0,shellcon.CSIDL_STARTUP))
    shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, \
        shell.IID_IShellLink)
    shortcut.SetPath(os.getcwd()+'\\Email My PC Launcher.exe')
    shortcut.SetWorkingDirectory(os.getcwd())
    shortcut.SetIconLocation(os.getcwd()+'\\ui\\images\\Icon.ico',0)
    shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(startup_path+'\\Emai My PC.lnk',0)

#??????????
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def _cat_registrar():
  return pythoncom.CoCreateInstance(
    pythoncom.CLSID_StdComponentCategoriesMgr,
    None,
    pythoncom.CLSCTX_INPROC_SERVER,
    pythoncom.IID_ICatRegister
    )
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def testVTableInProc(self):
        # We used to crash running this the second time - do it a few times
        for i in range(3):
            progress("Testing VTables in-process #%d..." % (i+1))
            TestVTable(pythoncom.CLSCTX_INPROC_SERVER)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def _cat_registrar():
  return pythoncom.CoCreateInstance(
    pythoncom.CLSID_StdComponentCategoriesMgr,
    None,
    pythoncom.CLSCTX_INPROC_SERVER,
    pythoncom.IID_ICatRegister
    )
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def testVTableInProc(self):
        # We used to crash running this the second time - do it a few times
        for i in range(3):
            progress("Testing VTables in-process #%d..." % (i+1))
            TestVTable(pythoncom.CLSCTX_INPROC_SERVER)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def createListener(self, oImplClass, dArgs):
        if True:
            raise Exception('no active listeners on Windows as PyGatewayBase::QueryInterface() '
                            'returns new gateway objects all the time, thus breaking EventQueue '
                            'assumptions about the listener interface pointer being constants between calls ')
        # Did this code ever really work?
        d = {}
        d['BaseClass'] = oImplClass
        d['dArgs'] = dArgs
        d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID
        d['tlb_major'] = PlatformMSCOM.VBOX_TLB_MAJOR
        d['tlb_minor'] = PlatformMSCOM.VBOX_TLB_MINOR
        str_ = ""
        str_ += "import win32com.server.util\n"
        str_ += "import pythoncom\n"

        str_ += "class ListenerImpl(BaseClass):\n"
        str_ += "   _com_interfaces_ = ['IEventListener']\n"
        str_ += "   _typelib_guid_ = tlb_guid\n"
        str_ += "   _typelib_version_ = tlb_major, tlb_minor\n"
        str_ += "   _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER\n"
        # Maybe we'd better implement Dynamic invoke policy, to be more flexible here
        str_ += "   _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n"

        # capitalized version of listener method
        str_ += "   HandleEvent=BaseClass.handleEvent\n"
        str_ += "   def __init__(self): BaseClass.__init__(self, dArgs)\n"
        str_ += "result = win32com.server.util.wrap(ListenerImpl())\n"
        exec(str_, d, d)
        return d['result']
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def DumpLink(fname):
    shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
    persistFile.Load(fname,STGM_READ)
    shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
    fname, findData = shellLink.GetPath(0)
    print "Filename:", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
    print "Description:", shellLink.GetDescription()
    print "Working Directory:", shellLink.GetWorkingDirectory()
    print "Icon:", shellLink.GetIconLocation()
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_InternetShortcut, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IUniformResourceLocator
        )
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def testVTableInProc(self):
        # We used to crash running this the second time - do it a few times
        for i in range(3):
            progress("Testing VTables in-process #%d..." % (i+1))
            TestVTable(pythoncom.CLSCTX_INPROC_SERVER)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DumpLink(fname):
    shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
    persistFile.Load(fname,STGM_READ)
    shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
    fname, findData = shellLink.GetPath(0)
    print("Filename:", fname, ", UNC=", shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0])
    print("Description:", shellLink.GetDescription())
    print("Working Directory:", shellLink.GetWorkingDirectory())
    print("Icon:", shellLink.GetIconLocation())
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def __init__( self ):
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_InternetShortcut, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IUniformResourceLocator
        )
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def _cat_registrar():
  return pythoncom.CoCreateInstance(
    pythoncom.CLSID_StdComponentCategoriesMgr,
    None,
    pythoncom.CLSCTX_INPROC_SERVER,
    pythoncom.IID_ICatRegister
    )
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def main(): 
    hwnd = 0

    # Create an instance of the object picker. 
    picker = pythoncom.CoCreateInstance(adsi.CLSID_DsObjectPicker,
                                None,
                                pythoncom.CLSCTX_INPROC_SERVER,
                                adsi.IID_IDsObjectPicker)

    # Create our scope init info.
    siis = adsi.DSOP_SCOPE_INIT_INFOs(1)
    sii = siis[0]

    # Combine multiple scope types in a single array entry.

    sii.type = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | \
               DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN

    # Set uplevel and downlevel filters to include only computer objects.
    # Uplevel filters apply to both mixed and native modes.
    # Notice that the uplevel and downlevel flags are different.

    sii.filterFlags.uplevel.bothModes = DSOP_FILTER_COMPUTERS
    sii.filterFlags.downlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS

    # Initialize the interface.
    picker.Initialize(
        None, # Target is the local computer.
        siis, # scope infos
        DSOP_FLAG_MULTISELECT, # options
        ('objectGUID','displayName') ) # attributes to fetch

    do = picker.InvokeDialog(hwnd)
    # Extract the data from the IDataObject.
    format_etc = (cf_objectpicker, None,
                  pythoncom.DVASPECT_CONTENT, -1,
                  pythoncom.TYMED_HGLOBAL)
    medium = do.GetData(format_etc)
    data = adsi.StringAsDS_SELECTION_LIST(medium.data)
    for item in data:
        name, klass, adspath, upn, attrs, flags = item
        print "Item", name
        print " Class:", klass
        print " AdsPath:", adspath
        print " UPN:", upn
        print " Attrs:", attrs
        print " Flags:", flags
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def main(): 
    hwnd = 0

    # Create an instance of the object picker. 
    picker = pythoncom.CoCreateInstance(adsi.CLSID_DsObjectPicker,
                                None,
                                pythoncom.CLSCTX_INPROC_SERVER,
                                adsi.IID_IDsObjectPicker)

    # Create our scope init info.
    siis = adsi.DSOP_SCOPE_INIT_INFOs(1)
    sii = siis[0]

    # Combine multiple scope types in a single array entry.

    sii.type = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | \
               DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN

    # Set uplevel and downlevel filters to include only computer objects.
    # Uplevel filters apply to both mixed and native modes.
    # Notice that the uplevel and downlevel flags are different.

    sii.filterFlags.uplevel.bothModes = DSOP_FILTER_COMPUTERS
    sii.filterFlags.downlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS

    # Initialize the interface.
    picker.Initialize(
        None, # Target is the local computer.
        siis, # scope infos
        DSOP_FLAG_MULTISELECT, # options
        ('objectGUID','displayName') ) # attributes to fetch

    do = picker.InvokeDialog(hwnd)
    # Extract the data from the IDataObject.
    format_etc = (cf_objectpicker, None,
                  pythoncom.DVASPECT_CONTENT, -1,
                  pythoncom.TYMED_HGLOBAL)
    medium = do.GetData(format_etc)
    data = adsi.StringAsDS_SELECTION_LIST(medium.data)
    for item in data:
        name, klass, adspath, upn, attrs, flags = item
        print("Item", name)
        print(" Class:", klass)
        print(" AdsPath:", adspath)
        print(" UPN:", upn)
        print(" Attrs:", attrs)
        print(" Flags:", flags)