Sunday, July 29, 2007

Logical Drive Enumeration in IronPython

The .Net framework has a lot of useful low level functionality in it that is kept well hidden. Writing in C# or C++/CLI, the temptation is there to P/Invoke the obvious Win32 APIs rather than go burrowing into the unexpected parts of the system. And while we could compile ourselves some P/Invoke C# on the fly in IronPython, that's sufficiently inaesthetic to make it worthwhile looking for another way.

And behold--

which gives, when I run it

['C:', 'D:', 'E:', 'F:', 'G:', 'H:', 'I:', 'J:', 'K:', 'L:', 'N:']

There is a lot of good stuff in the WMI classes, but finding the query strings is a bit of a black art...

Post a Comment