Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Listing partitions (on win32)

Reply
Thread Tools

Listing partitions (on win32)

 
 
Claude Henchoz
Guest
Posts: n/a
 
      01-15-2006
Hi

Is there any way of listing partitions on a (win32) computer without
using WMI?

Cheers, Claude

 
Reply With Quote
 
 
 
 
Bengt Richter
Guest
Posts: n/a
 
      01-15-2006
On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <(E-Mail Removed)> wrote:

>Hi
>
>Is there any way of listing partitions on a (win32) computer without
>using WMI?
>

Maybe this will work (I skipped A: and B:, but you can include them if
you want to catch floppy drives with something in them). The 'xxx' is just so as
not to get a full directory's worth of useless text. If xxx happens to be defined
it doesn't hurt anything. It's not going to be as fast as using one of the
win32 api packages to get at GetLogicalDriveStrings, but this works on my NT4:
(error messages apparently go to stderr, so stdout gets '' which makes the if fail)

>>> def fakeGetLogicalDriveStrings():

... return [c+':' for c in (chr(n) for n in xrange(ord('A'), ord('Z')+1))
... if os.popen('dir %s:\\xxx'%c).read()]
...
>>> fakeGetLogicalDriveStrings()

['C:', 'D:', 'E:', 'V:', 'W:']

Regards,
Bengt Richter
 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      01-15-2006
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

 
Reply With Quote
 
bonono@gmail.com
Guest
Posts: n/a
 
      01-15-2006

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
>>>


 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      01-15-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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).

Just to make it plain: it's no skin off my nose at all. I
don't get offended because someone doesn't want to
use WMI. I'm merely curious as to whether it was
because the wmi module was too hard, or whether
the machines were Win9x or NT, where you have to
go out of your way to install WMI, or whether there
was some other reason.

Tim

 
Reply With Quote
 
bonono@gmail.com
Guest
Posts: n/a
 
      01-15-2006

Tim Golden wrote:
> (E-Mail Removed) 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).
>
> Just to make it plain: it's no skin off my nose at all. I
> don't get offended because someone doesn't want to
> use WMI. I'm merely curious as to whether it was
> because the wmi module was too hard, or whether
> the machines were Win9x or NT, where you have to
> go out of your way to install WMI, or whether there
> was some other reason.
>

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.

 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      01-15-2006
(E-Mail Removed) wrote:
> Tim Golden wrote:
>> (E-Mail Removed) 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
 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      01-15-2006
Claude Henchoz wrote:
> Hi
>
> Is there any way of listing partitions on a (win32) computer without
> using WMI?


It looks as though XP has a command-line utility
called diskpart.exe which should be able to do
this kind of thing. I've no experience with it
myself, but assuming that it outputs information
to screen, it should be easy to pull that back
into Python with os.popen or the subprocess module.

TJG
 
Reply With Quote
 
Roger Upole
Guest
Posts: n/a
 
      01-15-2006

"Claude Henchoz" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) ups.com...
> Hi
>
> Is there any way of listing partitions on a (win32) computer without
> using WMI?
>
> Cheers, Claude
>


Using win32file.DeviceIOControl with IOCTL_DISK_GET_DRIVE_LAYOUT
as the control code should be able to retrieve the partitions
defined on a disk.
http://msdn.microsoft.com/library/de...ive_layout.asp
Unpacking the output buffer may get a little messy, though.

hth
Roger



----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
Reply With Quote
 
Roger Upole
Guest
Posts: n/a
 
      01-15-2006

"Bengt Richter" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <(E-Mail Removed)> wrote:
>
>>Hi
>>
>>Is there any way of listing partitions on a (win32) computer without
>>using WMI?
>>

> Maybe this will work (I skipped A: and B:, but you can include them if
> you want to catch floppy drives with something in them). The 'xxx' is just so as
> not to get a full directory's worth of useless text. If xxx happens to be defined
> it doesn't hurt anything. It's not going to be as fast as using one of the
> win32 api packages to get at GetLogicalDriveStrings, but this works on my NT4:
> (error messages apparently go to stderr, so stdout gets '' which makes the if fail)
>
> >>> def fakeGetLogicalDriveStrings():

> ... return [c+':' for c in (chr(n) for n in xrange(ord('A'), ord('Z')+1))
> ... if os.popen('dir %s:\\xxx'%c).read()]
> ...
> >>> fakeGetLogicalDriveStrings()

> ['C:', 'D:', 'E:', 'V:', 'W:']
>
> Regards,
> Bengt Richter


This will miss any partitions that don't have a drive letter assigned.
It will also give duplicate results for any volumes that have more
than one drive letter. And it will return an entry for CD or DVD
drives which aren't disk partitions.

Roger



----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File util API to move files accross partitions/filesystems dwi2004@gmail.com Java 11 11-19-2005 12:37 AM
Generating all partitions of a set megaduks@tlen.pl Java 7 09-05-2005 03:40 AM
Partitions (system recovery) =?Utf-8?B?VGFubmVyIEYu?= Microsoft Certification 0 04-18-2004 08:56 AM
Q on Computer Mngmnt and Partitions mharris MCSE 2 02-08-2004 11:31 PM
OT Resizing partitions Rick MCSE 0 09-29-2003 04:36 PM



Advertisments