I'm working on an AutoIt script where I have the disk number, partition number, and label, and I need to find the corresponding drive letter. I've tried several approaches, but none seem to work consistently. Here's the current code:
$query = "SELECT DriveLetter FROM Win32_DiskDriveToDiskPartition WHERE DiskNumber = " & $targetDiskNumber & _
" AND PartitionNumber = " & $targetPartitionNumber & _
" AND Name = '" & $targetLabel & "'"
$result = $WMBIObj.ExecQuery($query)
The variables $diskNumber, $partitionNumber, and $label are known. Can someone help me with a reliable method to find the drive letter associated with the specified disk number, partition number, and label?
I'm using the Win32_DiskPartition and Win32_LogicalDisk classes via WMI in AutoIt. The label refers to the volume label of the partition. The script should work on various Windows systems.
here complete solution