On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <claude.henchoz @gmail.com> wrote:
[color=blue]
>Hi
>
>Is there any way of listing partitions on a (win32) computer without
>using WMI?
>[/color]
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 GetLogicalDrive Strings, but this works on my NT4:
(error messages apparently go to stderr, so stdout gets '' which makes the if fail)
[color=blue][color=green][color=darkred]
>>> def fakeGetLogicalD riveStrings():[/color][/color][/color]
... return [c+':' for c in (chr(n) for n in xrange(ord('A') , ord('Z')+1))
... if os.popen('dir %s:\\xxx'%c).re ad()]
...[color=blue][color=green][color=darkred]
>>> fakeGetLogicalD riveStrings()[/color][/color][/color]
['C:', 'D:', 'E:', 'V:', 'W:']
Tim Golden wrote:[color=blue]
> Claude Henchoz wrote:
>[color=green]
> > Is there any way of listing partitions on a (win32) computer without
> > using WMI?[/color]
>
> Not that this answers your question, but why _don't_ you
> want to use WMI?
>
> TJG[/color]
[color=blue][color=green][color=darkred]
>>> import wmi[/color][/color][/color]
Traceback (most recent call last):
File "<pyshell#0 >", line 1, in -toplevel-
import wmi
ImportError: No module named wmi[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
bonono@gmail.co m wrote:[color=blue]
> Tim Golden wrote:[color=green]
> > Claude Henchoz wrote:
> >[color=darkred]
> > > Is there any way of listing partitions on a (win32) computer without
> > > using WMI?[/color]
> >
> > Not that this answers your question, but why _don't_ you
> > want to use WMI?
> >
> > TJG[/color]
>[color=green][color=darkred]
> >>> import wmi[/color][/color]
>
> Traceback (most recent call last):
> File "<pyshell#0 >", line 1, in -toplevel-
> import wmi
> ImportError: No module named wmi[color=green][color=darkred]
> >>>[/color][/color][/color]
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 Golden wrote:[color=blue]
> bonono@gmail.co m wrote:[color=green]
> > Tim Golden wrote:[color=darkred]
> > > 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[/color]
> >[color=darkred]
> > >>> import wmi[/color]
> >
> > Traceback (most recent call last):
> > File "<pyshell#0 >", line 1, in -toplevel-
> > import wmi
> > ImportError: No module named wmi[color=darkred]
> > >>>[/color][/color]
>
> 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.
>[/color]
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.
Why/Why not WMI [was: Listing partitions (on win32)]
bonono@gmail.co m wrote:[color=blue]
> Tim Golden wrote:[color=green]
>> bonono@gmail.co m wrote:[color=darkred]
>>> 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[/color]
>> 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).[/color][/color]
[color=blue]
> 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.[/color]
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.
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.
Claude Henchoz wrote:[color=blue]
> Hi
>
> Is there any way of listing partitions on a (win32) computer without
> using WMI?[/color]
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.
"Claude Henchoz" <claude.henchoz @gmail.com> wrote in message news:1137286353 .204837.31580@z 14g2000cwz.goog legroups.com...[color=blue]
> Hi
>
> Is there any way of listing partitions on a (win32) computer without
> using WMI?
>
> Cheers, Claude
>[/color]
Using win32file.Devic eIOControl 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 =----
"Bengt Richter" <bokr@oz.net> wrote in message news:43ca001d.1 137679376@news. oz.net...[color=blue]
> On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <claude.henchoz @gmail.com> wrote:
>[color=green]
>>Hi
>>
>>Is there any way of listing partitions on a (win32) computer without
>>using WMI?
>>[/color]
> 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 GetLogicalDrive Strings, but this works on my NT4:
> (error messages apparently go to stderr, so stdout gets '' which makes the if fail)
>[color=green][color=darkred]
> >>> def fakeGetLogicalD riveStrings():[/color][/color]
> ... return [c+':' for c in (chr(n) for n in xrange(ord('A') , ord('Z')+1))
> ... if os.popen('dir %s:\\xxx'%c).re ad()]
> ...[color=green][color=darkred]
> >>> fakeGetLogicalD riveStrings()[/color][/color]
> ['C:', 'D:', 'E:', 'V:', 'W:']
>
> Regards,
> Bengt Richter[/color]
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 =----
Why I don't want to rely on WMI:
I am wanting to use this under Windows PE, and although I can include
WMI, I just wanted to find out whether there is a way to not use it.
Another thing:
I really do want to also get the partitions that do _not_ have an
associated drive letter.
All in all:
I am probably going to have to write something with tempfile that uses
diskpart.exe to use this. Although this will get ugly, it seems to be
the best way (the best way without WMI, that is).
On Sun, 15 Jan 2006 08:08:16 -0500, "Roger Upole" <rupole@hotmail .com> wrote:
[color=blue]
>
>"Bengt Richter" <bokr@oz.net> wrote in message news:43ca001d.1 137679376@news. oz.net...[color=green]
>> On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <claude.henchoz @gmail.com> wrote:
>>[color=darkred]
>>>Hi
>>>
>>>Is there any way of listing partitions on a (win32) computer without
>>>using WMI?
>>>[/color]
>> 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 GetLogicalDrive Strings, but this works on my NT4:
>> (error messages apparently go to stderr, so stdout gets '' which makes the if fail)
>>[color=darkred]
>> >>> def fakeGetLogicalD riveStrings():[/color]
>> ... return [c+':' for c in (chr(n) for n in xrange(ord('A') , ord('Z')+1))
>> ... if os.popen('dir %s:\\xxx'%c).re ad()]
>> ...[color=darkred]
>> >>> fakeGetLogicalD riveStrings()[/color]
>> ['C:', 'D:', 'E:', 'V:', 'W:']
>>
>> Regards,
>> Bengt Richter[/color]
>
>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.
>[/color]
Yes, I guess I wasn't paying attention to the focus on partitions.
I wonder if you could try opening the physical disks (there is a weird
path prefix syntax IIRC) and read and interpret MBRs etc. for yourself.
Of course, you would need privilege to open raw disk reading, and you
definitely wouldn't want to make a mistake about read vs write ;-)
If ctypes becomes standard amongst the batteries included, this kind of
stuff should get easier, since I suppose you could use it to get to the
APIs you suggest (DeviceIoContro l with IOCTL_DISK_GET_ DRIVE_LAYOUT).
Kind of scary the damage you could do as administrator though, given that
on windows people tend to wind up running as administrator by default if they own
the machine ;-/
Comment