Why/Why not WMI [was: Listing partitions (on win32)]

Tim Golden news at timgolden.me.uk
Sun Jan 15 05:50:25 EST 2006


bonono at gmail.com wrote:
> Tim Golden wrote:
>> bonono at gmail.com wrote:
>>> Tim Golden wrote:
>>>> Claude Henchoz wrote:
>>>>
>>>>> Is there any way of listing partitions on a (win32) computer without
>>>>> using WMI?
>>>> Not that this answers your question, but why _don't_ you
>>>> want to use WMI?
>>>>
>>>> TJG
>>>>>> import wmi
>>> Traceback (most recent call last):
>>>   File "<pyshell#0>", line 1, in -toplevel-
>>>     import wmi
>>> ImportError: No module named wmi
>> It's quite possible to do WMI in Python without using
>> the wmi module -- all the module does is to hide some
>> slightly messy plumbing. But the OP doesn't suggest
>> that he's unwilling to install anything, merely to *use*
>> WMI. (Unless you _are_ the OP under a different alias).

> I am not him, but just another data point(possibly reason) of why one
> doesn't want to use it. It is not intended to be a post of "wmi suck".
> In fact, when I first saw the post about wmi module, I immediate tried
> to query my XP using it but once I saw the above, I gave up.

Fair enough. You'd need to install the pywin32 extensions
and then the wmi module on top of that. But I suppose that
because I simply install pywin32 on any Windows box as soon
as I install Python, I assumed others did the same. Not
necessarily the case, obviously. Also, I'm obviously
guaranteed to have the wmi module available since I'm
its author, but again not everyone has.

Just in case you're interested in trying it out:
http://timgolden.me.uk/python/wmi.html

I think the thing with WMI -- the mechanism, not the module --
is that you can do lots of things easily, or at least
consistently, which are painful otherwise. Sometimes
people will ask, eg "How do I copy a file with WMI?"
and I'm inclined to say: unless you have some very
specific requirement, you probably don't want to use
WMI to do that. But for certain things, it's just so
easy -- and there are examples and recipes for it all
over the web -- that it just makes sense.

Tim



More information about the Python-list mailing list