July 05, 2005
Listing shell windows

Having read Raymond Chen's Using script to query information from Internet Explorer windows, well, how could I resist?

import win32com.client
shell = win32com.client.gencache.EnsureDispatch("Shell.Application")
windows = shell.Windows()
for window in (windows.Item(index) for index in range(1, windows.Count+1)):
    if window:
        print window.LocationName, '=', window.LocationURL

Quite pointless, but there you are.

There are other fun things you can do with the shell interfact, too, like opening exporer windows pointing to the directory of your choice - shell.Explore(r'C:\projects\morph') - or opening up control panel items - shell.ControlPanelItem('timedate.cpl') - but they are mostly pretty pointless too. I can think of uses for some things, I suppose - shell.IsServiceRunning('Tomcat5') might come in handy, along with ServiceStop and ServiceStart.

You can find some of this stuff documented in MSDN - Shell Object and IShellDispatch2 Object.

Posted to Python by Simon Brunning at July 05, 2005 04:03 PM
Post a comment

Email Address:



Remember info?