473,804 Members | 2,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listing partitions (on win32)

Hi

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

Cheers, Claude

Jan 15 '06 #1
11 1879
On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <cl************ @gmail.com> 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 GetLogicalDrive Strings, but this works on my NT4:
(error messages apparently go to stderr, so stdout gets '' which makes the if fail)
def fakeGetLogicalD riveStrings(): ... 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()]
... fakeGetLogicalD riveStrings()

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

Regards,
Bengt Richter
Jan 15 '06 #2
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

Jan 15 '06 #3

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


Jan 15 '06 #4
bo****@gmail.co m 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

Jan 15 '06 #5

Tim Golden wrote:
bo****@gmail.co m 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.

Jan 15 '06 #6
bo****@gmail.co m wrote:
Tim Golden wrote:
bo****@gmail.co m 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
Jan 15 '06 #7
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
Jan 15 '06 #8

"Claude Henchoz" <cl************ @gmail.com> wrote in message news:11******** *************@z 14g2000cwz.goog legroups.com...
Hi

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

Cheers, Claude


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 =----
Jan 15 '06 #9

"Bengt Richter" <bo**@oz.net> wrote in message news:43******** *********@news. oz.net...
On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <cl************ @gmail.com> 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 GetLogicalDrive Strings, but this works on my NT4:
(error messages apparently go to stderr, so stdout gets '' which makes the if fail)
def fakeGetLogicalD riveStrings(): ... 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()]
... fakeGetLogicalD riveStrings()

['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 =----
Jan 15 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2224
by: Steve | last post by:
This post has two parts. First is my feedback on sets. (Hello? Last summer called, they want their discussion thread back...) Second is some questions about my implementation of a partition function for sets. Part 1. --- >From: Raymond Hettinger (vze4rx4y@verizon.net) >Subject: Py2.3: Feedback on Sets >Newsgroups: comp.lang.python >Date: 2003-08-11 23:02:18 PST
5
4311
by: Nick J Chackowsky | last post by:
Wrote a python script to find the partitions of an integer (a list of all the ways you can express n as a sum of integers). For example, the partitions of 5 are 5 4+1 3+2 2+2+1 3+1+1 2+1+1+1 1+1+1+1+1
4
8467
by: Scaramouche | last post by:
is there an equivalent to unixs' ps command in perl? i was writing some win32 scripts and i needed a listing of specific processes. i could perhaps grep through a list of running processes but how can i attain that through perl? thanks
0
2133
by: Veli-Pekka Tätilä | last post by:
Hi, My first post here. I've found some serious accessibility flaws in the Python 2.4 docs and wish they could be rectified over time. I'm very new to Python and initially contacted docs at python org, However, I haven't gotten a reply for a week or so, and figured out I could post here for a larger audience, then. Original message follows: Hello,
3
2473
by: jcgeorge | last post by:
I have a Windows DPF (v8.2.2) environment. 2 Nodes 5 Partitions Server1 - Cat (0) Data (1) Data (2) Server2 - Data (3) Data (4) I want to use block-based IO, but I do not want the same size block area of the bufferpool in each partition, I want a smaller value in the catalog partition - because the bufferpool size is much smaller.
3
2713
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include directories contain a file named "cppfile1.h". In my main project I #include "cppfile1.h". I rely on the order of paths in additional include directories list to get file cppfile1.h from ProjectA and
7
4752
by: JohnR | last post by:
Couldn't find it in MSDN. Does anybody have a listing of the message constants that would be received in my application.addmessagefilter routine in VB.net? They are referred to all over MSDN but I can't locate the actual listing of the constants and their values. Thanks, John
8
1650
by: arunrocks | last post by:
Hi I am having a requirement to create a db in 2 out of 8 partitiones. I have the following doubts. 1. should I create a new instance in 2 partitions alone (the present instance spans 8 nodes) 2. or is there a way to create the db in 2 out of 8. If I have to create a new instance, (its a BCU from IBM) I;d be happy if someone would link a material (1st time I am working in a partitioned env) Should I execute db2icrt in each of the...
1
27808
Nepomuk
by: Nepomuk | last post by:
In most modern distributions of Linux and Unix (at least ones with graphical environments like KDE, Gnome or XFCE), you get to mount your partitions easily from the desktop. In some cases however, it isn't that easy. Note, that all of these commands have to be run in a terminal as root user. To open a terminal (sometimes called a console), either press ALT+F2 and type xterm (alternatives could be konsole or terminal) or press CRTL+ALT+F1 to...
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.