Roman
Roman

Reputation:

how to obtain physical drives in Windows

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

Upvotes: 2

Views: 6512

Answers (4)

Alex Okrushko
Alex Okrushko

Reputation: 7372

How about Win32_DiskDrive wmi class?

c = wmi.WMI()

dd = c.Win32_DiskDrive()[0]

print.dd

More about Win32_DiskDrive on the msdn

Upvotes: 0

Kirill Titov
Kirill Titov

Reputation: 2109

Also you can try win32 module for Python.

Upvotes: 1

Vinay Sajip
Vinay Sajip

Reputation: 99365

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.

Upvotes: 3

user180247
user180247

Reputation:

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.

Upvotes: 1

Related Questions