in reply to Windows drive letter mapping question

I think what you want is better found in Win32::DriveInfo than in Win32::OLE.

I think it might be possible from Win32::OLE, but I'm not good enough with Windows APIs to tell you how. There's good information on how to do it from the C API at "How to get the PhysicalDrive number which the logical drive locate:". If you can figure out how that translates to Perl, then hopefully it will help, but I'd recommend trying the existing wheel first.

  • Comment on Re: Windows drive letter mapping question

Replies are listed 'Best First'.
Re^2: Windows drive letter mapping question
by AnthonyC (Novice) on Apr 15, 2008 at 15:09 UTC
    I tried looking at Win32::DriveInfo and that did not have all the information I needed. The Serial Number listed there is volume S/N, not physical S/N. I checked out that other link, but I had NO idea how to implement it in Perl.

    I did some digging on WMI in the MSDN and found what I need, but it isn't pretty.

    Drive letter info is given at the Win32_LogicalDisk level. The tree from there is as follows:
    Win32_LogicalDiskToPartition links to
    Win32_DiskPartition, which is referenced by
    Win32_DiskDriveToDiskPartition, which links to
    Win32_DiskDrive, which is referenced by
    Win32_DiskDrivePhysicalMedia, which links to
    Win32_PhysicalMedia, which has the actual hardware S/N.

    Whew! :) So that ain't gonna be pretty, but all the data is there.

    I also saw that newer versions of windows have access to the Win_32_Volume class, which links drive letter to a weird volume string (which looks like a registry entry). However, I could not find how that maps to a physical device, which is the only way, apparently, to get the HW S/N.

    Thanks for the help so far. If anyone has any more advice on shortcuts or different approaches, I'm all ears. Until then, I will plug away at this. --Anthony