Pithy and Readable? Do tell!

Wed, Feb 22, 2006 2-minute read

A long time ago, Raymond Chen wrote about how to interact with the ShellWindows COM object using C++.  It was doable, but clumsy.  He then revisited his post, showing how much easier it was when accessed through a scripting language as its designers had intended.  As can be expected, the comments flowed fast and furious in illustration of the conciseness of various languages that the readers were fond of.

I’ve been meaning to show the Monad equivalent – not just because it is pithy, but because it is pithy and meaningful.  As MOW points out, it is amazing how frequently this happens.

The purpose: list the title and location of all open explorer windows:

MSH:46 > (new-object -com "Shell.Application").Windows() |
    select LocationName,LocationUrl

LocationName                            LocationURL
------------                            -----------
Smash Dance Hits                        file:///H:/lee/My%20Music/Dance/Vari...
scriptomatic                            file:///C:/temp/scriptomatic
Administrative Tools                    file:///C:/Documents%20and%20Setting...
The Old New Thing : Using script to ... http://blogs.msdn.com/oldnewthing/ar...

Vivek makes a similar point in his latest post: It’s a one line world.  You don’t need to be a scripting guru to unleash the power of Monad:

When we started designing the Exchange cmdline and scripting interface, we made absolutely sure that 80% of our customers, who normally have little or no scripting experience, can still use Monad/Exchange cmdline to auotmate or perform their tasks.
You can write lots of complicated scripts, but the majority of time, you simply have to construct a one or two line pipeline.

[Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]