Python pythoncom.CoCreateInstance() Examples

The following are 30 code examples of pythoncom.CoCreateInstance(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pythoncom , or try the search function .
Example #1
Source File: debugger.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def __init__(self, interfaceMaker = None, processName = None):
        if processName is None: processName = "Python Process"
        if interfaceMaker is None: interfaceMaker = SimpleHostStyleInterfaceMaker()

        self.pydebugger = adb.Debugger()

        self.pdm=pythoncom.CoCreateInstance(axdebug.CLSID_ProcessDebugManager,None,pythoncom.CLSCTX_ALL, axdebug.IID_IProcessDebugManager)

        self.app, self.root = interfaceMaker.MakeInterfaces(self.pdm)
        self.app.SetName(processName)
        self.interfaceMaker = interfaceMaker

        expressionProvider = _wrap(expressions.ProvideExpressionContexts(), axdebug.IID_IProvideExpressionContexts)
        self.expressionCookie = self.app.AddGlobalExpressionContextProvider(expressionProvider)

        contProvider = CodeContainerProvider(self)
        self.pydebugger.AttachApp(self.app, contProvider) 
Example #2
Source File: shortcut.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #3
Source File: testPyComTest.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def TestVTableMI():
    clsctx = pythoncom.CLSCTX_SERVER
    ob = pythoncom.CoCreateInstance("Python.Test.PyCOMTestMI", None, clsctx, pythoncom.IID_IUnknown)
    # This inherits from IStream.
    ob.QueryInterface(pythoncom.IID_IStream)
    # This implements IStorage, specifying the IID as a string
    ob.QueryInterface(pythoncom.IID_IStorage)
    # IDispatch should always work
    ob.QueryInterface(pythoncom.IID_IDispatch)
    
    iid = pythoncom.InterfaceNames["IPyCOMTest"]
    try:
        ob.QueryInterface(iid)
    except TypeError:
        # Python can't actually _use_ this interface yet, so this is
        # "expected".  Any COM error is not.
        pass 
Example #4
Source File: testShell.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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" 
Example #5
Source File: shortcut.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
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) 
Example #6
Source File: shortcut.py    From BitTorrent with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #7
Source File: testcomext.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 6 votes vote down vote up
def CreateShortCut(Path, Target,Arguments = "", StartIn = "", Icon = ("",0), Description = ""):
    # Get the shell interface.
    sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \
        pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)

    # Get an IPersist interface
    persist = sh.QueryInterface(pythoncom.IID_IPersistFile)

    # Set the data
    sh.SetPath(Target)
    sh.SetDescription(Description)
    sh.SetArguments(Arguments)
    sh.SetWorkingDirectory(StartIn)
    sh.SetIconLocation(Icon[0],Icon[1])
#    sh.SetShowCmd( win32con.SW_SHOWMINIMIZED)

    # Save the link itself.
    persist.Save(Path, 1)
    print "Saved to", Path 
Example #8
Source File: Shortcut.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def Get(cls, filename):
        sh = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink,
            None,
            pythoncom.CLSCTX_INPROC_SERVER,
            shell.IID_IShellLink
        )
        persist = sh.QueryInterface(pythoncom.IID_IPersistFile).Load(filename)  # NOQA
        self = cls()
        self.path = filename
        self.target = sh.GetPath(shell.SLGP_SHORTPATH)[0]
        self.description = sh.GetDescription()
        self.arguments = sh.GetArguments()
        self.startIn = sh.GetWorkingDirectory()
        self.icons = sh.GetIconLocation()
        return self 
Example #9
Source File: Shortcut.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def Create(
        cls,
        path,
        target,
        arguments="",
        startIn="",
        icon=("", 0),
        description=""
    ):
        """Create a Windows shortcut:

        path - As what file should the shortcut be created?
        target - What command should the desktop use?
        arguments - What arguments should be supplied to the command?
        startIn - What folder should the command start in?
        icon - (filename, index) What icon should be used for the shortcut?
        description - What description should the shortcut be given?

        eg
        Shortcut.Create(
            path=os.path.join (desktop (), "PythonI.lnk"),
            target=r"c:\python\python.exe",
            icon=(r"c:\python\python.exe", 0),
            description="Python Interpreter"
        )
        """
        sh = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink,
            None,
            pythoncom.CLSCTX_INPROC_SERVER,
            shell.IID_IShellLink
        )
        sh.SetPath(target)
        sh.SetDescription(description)
        sh.SetArguments(arguments)
        sh.SetWorkingDirectory(startIn)
        sh.SetIconLocation(icon[0], icon[1])
        persist = sh.QueryInterface(pythoncom.IID_IPersistFile)
        persist.Save(path, 1) 
Example #10
Source File: keyboard_recording_trojan.py    From keyboard_recording_trojan with MIT License 5 votes vote down vote up
def set_shortcut(filename,lnkname,iconname):
    shortcut = pythoncom.CoCreateInstance(
    shell.CLSID_ShellLink, None,
    pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
    shortcut.SetPath(filename)
    shortcut.SetIconLocation(iconname,0)
    if os.path.splitext(lnkname)[-1] != '.lnk':
        lnkname += ".lnk"
    shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(lnkname,0)
    
#如果是远程监听某个电脑,可以将获取到的信息通过邮件发出去 
Example #11
Source File: Email My PC.py    From Email_My_PC with MIT License 5 votes vote down vote up
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)

#删除开机启动快捷方式 
Example #12
Source File: dump_link.py    From Email_My_PC with MIT License 5 votes vote down vote up
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() 
Example #13
Source File: IUniformResourceLocator.py    From Email_My_PC with MIT License 5 votes vote down vote up
def __init__( self ):
		self._base = pythoncom.CoCreateInstance(
			shell.CLSID_InternetShortcut, None,
			pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IUniformResourceLocator
		) 
Example #14
Source File: recipe-576437.py    From code with MIT License 5 votes vote down vote up
def __init__(self, lnkname):
        self.shortcut = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
        self.shortcut.QueryInterface(pythoncom.IID_IPersistFile).Load(lnkname) 
Example #15
Source File: utils.py    From winpython with MIT License 5 votes vote down vote up
def create_shortcut(
    path,
    description,
    filename,
    arguments="",
    workdir="",
    iconpath="",
    iconindex=0,
):
    """Create Windows shortcut (.lnk file)"""
    import pythoncom
    from win32com.shell import shell

    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)
    if not filename.endswith('.lnk'):
        filename += '.lnk'
    ipf.Save(filename, 0)


# =============================================================================
# Misc.
# ============================================================================= 
Example #16
Source File: create_link.py    From Email_My_PC with MIT License 5 votes vote down vote up
def __init__( self ):
		self._base = pythoncom.CoCreateInstance(
			shell.CLSID_ShellLink, None,
			pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
		) 
Example #17
Source File: windows_post_install.py    From GridCal with GNU General Public License v3.0 5 votes vote down vote up
def create_shortcut(path, description, filename,
                        arguments="", workdir="", iconpath="", iconindex=0):
        try:
            import pythoncom
        except ImportError:
            print("pywin32 is required to run this script manually",
                  file=sys.stderr)
            sys.exit(1)
        from win32com.shell import shell, shellcon  # analysis:ignore

        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. 
Example #18
Source File: shortcut.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def __init__(self,
                 path=None,
                 arguments=None,
                 description=None,
                 workingdir=None,
                 iconpath=None,
                 iconidx=0):
        """
        @param path: Location of the target
        @param arguments: If path points to an executable, optional arguments
                      to pass
        @param description: Human-readable description of target
        @param workingdir: Directory from which target is launched
        @param iconpath: Filename that contains an icon for the shortcut
        @param iconidx: If iconpath is set, optional index of the icon desired
        """
        self._base = pythoncom.CoCreateInstance(
            shell.CLSID_ShellLink, None,
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
        )
        if path is not None:
            self.SetPath(os.path.abspath(path))
        if arguments is not None:
            self.SetArguments(arguments)
        if description is not None:
            self.SetDescription(description)
        if workingdir is not None:
            self.SetWorkingDirectory(os.path.abspath(workingdir))
        if iconpath is not None:
            self.SetIconLocation(os.path.abspath(iconpath), iconidx) 
Example #19
Source File: testPyComTest.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def TestVTable(clsctx=pythoncom.CLSCTX_ALL):
    # Any vtable interfaces marked as dual *should* be able to be
    # correctly implemented as IDispatch.
    ob = win32com.client.Dispatch("Python.Test.PyCOMTest")
    TestLocalVTable(ob)
    # Now test it via vtable - use some C++ code to help here as Python can't do it directly yet.
    tester = win32com.client.Dispatch("PyCOMTest.PyCOMTest")
    testee = pythoncom.CoCreateInstance("Python.Test.PyCOMTest", None, clsctx, pythoncom.IID_IUnknown)
    # check we fail gracefully with None passed.
    try:
        tester.TestMyInterface(None)
    except pythoncom.com_error, details:
        pass
    # and a real object. 
Example #20
Source File: testGIT.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CreateGIT():
    return pythoncom.CoCreateInstance(pythoncom.CLSID_StdGlobalInterfaceTable,
                                      None,
                                      pythoncom.CLSCTX_INPROC,
                                      pythoncom.IID_IGlobalInterfaceTable) 
Example #21
Source File: register.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _cat_registrar():
  return pythoncom.CoCreateInstance(
    pythoncom.CLSID_StdComponentCategoriesMgr,
    None,
    pythoncom.CLSCTX_INPROC_SERVER,
    pythoncom.IID_ICatRegister
    ) 
Example #22
Source File: combrowse.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def GetSubList(self):
        win32ui.DoWaitCursor(1)
        catid, lcid, desc = self.myobject
        catinf=pythoncom.CoCreateInstance(pythoncom.CLSID_StdComponentCategoriesMgr,None,pythoncom.CLSCTX_INPROC,pythoncom.IID_ICatInformation)
        ret = []
        for clsid in util.Enumerator(catinf.EnumClassesOfCategories((catid,),())):
            ret.append(HLICLSID(clsid))
        win32ui.DoWaitCursor(0)

        return ret 
Example #23
Source File: dynamic.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _GetGoodDispatch(IDispatch, clsctx = pythoncom.CLSCTX_SERVER):
	if isinstance(IDispatch, _GoodDispatchTypes):
		try:
			IDispatch = pythoncom.connect(IDispatch)
		except pythoncom.ole_error:
			IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
	else:
		# may already be a wrapped class.
		IDispatch = getattr(IDispatch, "_oleobj_", IDispatch)
	return IDispatch 
Example #24
Source File: dump.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def dumpall():
    dm=pythoncom.CoCreateInstance(axdebug.CLSID_MachineDebugManager,None,pythoncom.CLSCTX_ALL, axdebug.IID_IMachineDebugManager)
    e=Enumerator(dm.EnumApplications())
    for app in e:
        print "Application: %s" % app.GetName()
        node = app.GetRootNode() # of type PyIDebugApplicationNode->PyIDebugDocumentProvider->PyIDebugDocumentInfo
        DumpDebugApplicationNode(node) 
Example #25
Source File: create_link.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def __init__( self ):
		self._base = pythoncom.CoCreateInstance(
			shell.CLSID_ShellLink, None,
			pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
		) 
Example #26
Source File: IUniformResourceLocator.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def __init__( self ):
		self._base = pythoncom.CoCreateInstance(
			shell.CLSID_InternetShortcut, None,
			pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IUniformResourceLocator
		) 
Example #27
Source File: testHost4Dbg.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def TestEngine():
  model = {'Test' : util.wrap(ObjectModel()) }
  scriptDir = "."
  site = MySite(model)
  pyEngine = site._AddEngine("Python")
#  pyEngine2 = site._AddEngine("Python")
  vbEngine = site._AddEngine("VBScript")
#  forthEngine = site._AddEngine("ForthScript")
  try:
#    code = open(os.path.join(scriptDir, "debugTest.4ths"),"rb").read()
#    forthEngine.AddCode(code)
    code = open(os.path.join(scriptDir, "debugTest.pys"),"rb").read()
    pyEngine.AddCode(code)
    code = open(os.path.join(scriptDir, "debugTest.vbs"),"rb").read()
    vbEngine.AddCode(code)
#    code = open(os.path.join(scriptDir, "debugTestFail.pys"),"rb").read()
#    pyEngine2.AddCode(code)

#    from win32com.axdebug import axdebug
#    sessionProvider=pythoncom.CoCreateInstance(axdebug.CLSID_DefaultDebugSessionProvider,None,pythoncom.CLSCTX_ALL, axdebug.IID_IDebugSessionProvider)
#    sessionProvider.StartDebugSession(None)
    
    raw_input("Press enter to continue")
 #   forthEngine.Start()
    pyEngine.Start() # Actually run the Python code
    vbEngine.Start() # Actually run the VB code
  except pythoncom.com_error, details:
    print "Script failed: %s (0x%x)" % (details[1], details[0])
  # Now run the code expected to fail!
#  try:
#    pyEngine2.Start() # Actually run the Python code that fails!
#    print "Script code worked when it should have failed."
#  except pythoncom.com_error:
#    pass 
Example #28
Source File: axsite.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def __init__(self, site, engine):
    self.eScript = self.eParse = self.eSafety = None
    if type(engine) == type(''):
      engine = pythoncom.CoCreateInstance(engine,
                                          None,
                                          pythoncom.CLSCTX_SERVER,
                                          pythoncom.IID_IUnknown)

    self.eScript = engine.QueryInterface(axscript.IID_IActiveScript)
    self.eParse = engine.QueryInterface(axscript.IID_IActiveScriptParse)
    self.eSafety = engine.QueryInterface(axscript.IID_IObjectSafety)

    self.eScript.SetScriptSite(site)
    self.eParse.InitNew() 
Example #29
Source File: debug.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def __init__(self, scriptEngine):
		self.scriptEngine = scriptEngine
		self.adb = adb.Debugger()
		self.rootNode = None
		self.debugApplication = None
		self.ccProvider = documents.CodeContainerProvider()
		try:
			self.scriptSiteDebug = scriptEngine.GetScriptSite(axdebug.IID_IActiveScriptSiteDebug)
		except pythoncom.com_error:
			# No debugger interface (ie, dumb host).  Do the extra work.
			trace("Scripting site has no debugger interface")
			self.scriptSiteDebug = None
		# Get the debug application object.
		self.debugApplication = None
		if self.scriptSiteDebug is not None:
			# Spec says that we should test for this, and if it fails revert to
			# PDM application.
			try:
				self.debugApplication = self.scriptSiteDebug.GetApplication()
				self.rootNode = self.scriptSiteDebug.GetRootApplicationNode()
			except pythoncom.com_error:
				self.debugApplication = None
				
		if self.debugApplication is None:
			# Try to get/create the default one
			# NOTE - Dont catch exceptions here - let the parent do it,
			# so it knows debug support is available.
			pdm=pythoncom.CoCreateInstance(axdebug.CLSID_ProcessDebugManager,None,pythoncom.CLSCTX_ALL, axdebug.IID_IProcessDebugManager)
			self.debugApplication = pdm.GetDefaultApplication()
			self.rootNode = self.debugApplication.GetRootNode()
			
		assert self.debugApplication is not None, "Need to have a DebugApplication object by now!"
		self.activeScriptDebug = None

		if self.debugApplication is not None:
			self.adb.AttachApp(self.debugApplication, self.ccProvider)
		self.codeContainers = {}
		self.activeScriptDebug = _wrap(ActiveScriptDebug(self, self.codeContainers), axdebug.IID_IActiveScriptDebug) 
Example #30
Source File: explorer_browser.py    From Email_My_PC with MIT License 4 votes vote down vote up
def __init__(self):
        message_map = {
                win32con.WM_DESTROY: self.OnDestroy,
                win32con.WM_COMMAND: self.OnCommand,
                win32con.WM_SIZE: self.OnSize,
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "test_explorer_browser"
        wc.lpfnWndProc = message_map # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(wc)
        # Create the Window.
        style = win32con.WS_OVERLAPPEDWINDOW | win32con.WS_VISIBLE
        self.hwnd = win32gui.CreateWindow( classAtom, "Python IExplorerBrowser demo", style, \
                0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
                0, 0, hinst, None)
        eb = pythoncom.CoCreateInstance(shellcon.CLSID_ExplorerBrowser, None, pythoncom.CLSCTX_ALL, shell.IID_IExplorerBrowser)
        # as per MSDN docs, hook up events early
        self.event_cookie = eb.Advise(wrap(EventHandler()))

        eb.SetOptions(shellcon.EBO_SHOWFRAMES)
        rect = win32gui.GetClientRect(self.hwnd)
        # Set the flags such that the folders autoarrange and non web view is presented
        flags = (shellcon.FVM_LIST, shellcon.FWF_AUTOARRANGE | shellcon.FWF_NOWEBVIEW)
        eb.Initialize(self.hwnd, rect, (0, shellcon.FVM_DETAILS))
        if len(sys.argv)==2:
            # If an arg was specified, ask the desktop parse it.
            # You can pass anything explorer accepts as its '/e' argument -
            # eg, "::{guid}\::{guid}" etc.
            # "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" is "My Computer"
            pidl = shell.SHGetDesktopFolder().ParseDisplayName(0, None, sys.argv[1])[1]
        else:
            # And start browsing at the root of the namespace.
            pidl = []
        eb.BrowseToIDList(pidl, shellcon.SBSP_ABSOLUTE)
        # and for some reason the "Folder" view in the navigator pane doesn't
        # magically synchronize itself - so let's do that ourself.
        # Get the tree control.
        sp = eb.QueryInterface(pythoncom.IID_IServiceProvider)
        try:
            tree = sp.QueryService(shell.IID_INameSpaceTreeControl,
                                   shell.IID_INameSpaceTreeControl)
        except pythoncom.com_error, exc:
            # this should really only fail if no "nav" frame exists...
            print "Strange - failed to get the tree control even though " \
                  "we asked for a EBO_SHOWFRAMES"
            print exc