Using the MagWMi shell and its single-line function (single-line - slow - but this is not the place where speed is required). I used it to create a list of 2-tier drives.
- HardDrive 1 → Letter 1, Letter 2
- HardDrive 2 → Letter 3, Letter 4
- NetServer 1 → Letter 5, Letter 6
- NetServer 2 → Letter 7, Letter 8
- Unrecognized → All other letters
But you must remember that some discs can be used without a letter. Thus, it will give you information about the root directories, but no more. Drive C: can be created on multiple physical drives. And some physical disks can be used without a letter at all.
unit WMI_Helper; interface function WMINetDiskName(const disk: string { 'C:' - w/o slash } ): string; function WMIPhysDiskName(const disk: string { 'C:' - w/o slash } ): string; function WMIGetVolumeName(const disk: string { 'C:' - w/o slash } ): string; implementation uses magwmi, SysUtils, StrUtils, Windows, IOUtils; function WMIGetProp(const query, param, resultProp: string): string; begin if MagWmiGetOneQ(StringReplace(query, '%s', param, []), resultProp, Result) <= 0 then Result := ''; Result := Trim(Result); end; function WMINetDiskName(const disk: string { 'C:' - w/o slash } ): string; const req = 'select ProviderName from Win32_MappedLogicalDisk where DeviceID = "%s"'; prop = 'ProviderName'; var i: integer; begin Result := WMIGetProp(req, disk, prop); If not TPath.IsUNCPath(Result) then exit(''); i := PosEx('\', TPath.GetPathRoot(Result), 3); if i <= 0 then exit(''); SetLength(Result, i - 1); end; function WMIPhysDiskName(const disk: string { 'C:' - w/o slash } ): string; const resultProp = 'DeviceID'; reqPart = 'ASSOCIATORS OF {Win32_LogicalDisk.DeviceID="%s"} WHERE ResultClass=Win32_DiskPartition'; reqDisk = 'ASSOCIATORS OF {Win32_DiskPartition.DeviceID="%s"} WHERE ResultClass=Win32_DiskDrive'; begin Result := WMIGetProp(reqPart, disk, resultProp); if Result > '' then Result := WMIGetProp(reqDisk, Result, resultProp); end; function WMIGetVolumeName(const disk: string { 'C:' - w/o slash } ): string; const prop = 'VolumeName'; reqNet = 'select VolumeName from Win32_MappedLogicalDisk where DeviceID = "%s"'; reqPhy = 'select VolumeName from Win32_LogicalDisk where DeviceID = "%s"'; begin Result := WMIGetProp(IfThen(GetDriveType(PChar(disk)) = DRIVE_REMOTE, reqNet, reqPhy), disk, prop); end; end.
source share