tags:

views:

444

answers:

4

I'm programming in Python with a wrapper of the kernel32 dll, so I can use any functions of this dll, like GetLogicalDrives(), for instance. I'm trying to obtain the information of the physical drives, even if they are not mounted. I've seen a question similar to this, but I need the information of the not mounted drives. All methods I've seen need a directory or a file in the device, but if it's not mounted, I can't have one, so the question is:

Is there a method which can provide me a list of the physical drives in the system, even if they are not mounted?

I have to say that using the Windows Registry, I've obtained the number of physical drives in "*HKEY_LOCAL_MACHINE\Hardware\Devicemap\Scsi\Scsi Port x*", because inside of this key, you can see the number of drives, including cd-rom devices or floppy devices. But I need size of the not mounted devices also, so...

A: 

FindFirstVolume and FindNextVolume may be what you need.

MSDN FindFirstVolume page

There's an example that searches for volumes and list all paths for each volume, and at first sight, it seems to allow the possibility that there is no such path for some volumes. That said, I've never used this.

Steve314
Thank you, but I've already used those methods, and they go through the volumes, instead of the hard disks. Besides, I call the QueryDosDeviceW method with the volume name returned by the FindNextVolume and I obtain the following:Volume name \\?\Volume{3118a200-a4ae-11...}\Physical disk: \Device\HarddiskVolume1Volume name \\?\Volume{3118a202-a4ae-11...}\Physical disk: \Device\HarddiskVolume2Volume name \\?\Volume{4f569545-a4af-11...}\Physical disk: \Device\CdRom0Volume name \\?\Volume{4f569544-a4af-11...}\Physical disk: \Device\Floppy0So the unmounted hard disk doesn't appear.
Roman
I think I understand. Volumes are partitions, but you want the actual disks, even if there are no partitions on them yet. I did some research out of curiosity, but all I found were DDK functions like SetupDiEnumDeviceInfo. Sounds like a dead end, but OTOH, diskpart.exe seems to link to that function.
Steve314
+3  A: 

Use Tim Golden's wmi module. Here's the cookbook entry:

import wmi

w = wmi.WMI()
for drive in w.Win32_LogicalDisk():
    print drive.Caption, drive.Size, drive.FreeSpace

prints

C: 99928924160 14214135808
D: None None
E: 499983122432 3380903936
S: 737329123328 362274299904
T: 737329123328 9654988800

However, note that no information is available for my D: drive (DVD drive, not mounted). I don't think you can get size info for removable media which isn't mounted.

Vinay Sajip
I believe Roman was asking about physical disks rather than logical one.
I. J. Kennedy
+1  A: 

Also you can try win32 module for Python.

Kirill Titov
A: 

http://msdn.microsoft.com/en-us/library/aa365730%28VS.85%29.aspx

GetLogicalDrives() GetLogicalDriveStrings()

Look like what you want. But they work off A:, B: C: etc, rather than \?\HardDisk or whatever

Pod