Jump to content

32bitcrusade

Members
  • Posts

    5
  • Joined

  • Last visited

Community Answers

  1. 32bitcrusade's post in Partition numbers to drive letters was marked as the answer   
    I found a solution to my problem after a bit of debugging. Basically, it's a bunch of For loops running in sequence to return the drive letter. Here's the code:


    $oWMISvc = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $colDiskDrives = $oWMISvc.ExecQuery("SELECT * FROM Win32_DiskDrive") For $oDiskDrive In $colDiskDrives $CurrentPhDisk = $oDiskDrive.DeviceId If $CurrentPhDisk = $CmdLine[1] Then ExitLoop EndIf Next ConsoleWrite("Selected right disk, selecting parition..." & @CRLF) $sQuery = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $CurrentPhDisk & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" $colPartitions = $oWMISvc.ExecQuery($sQuery) For $oPartition In $colPartitions $CurrentPartit = $oPartition.DeviceId $PCMD = StringRight($CurrentPartit, 1) If $PCMD = $CmdLine[2] Then ConsoleWrite("Selected partition: " & $CurrentPartit & @CRLF) ExitLoop EndIf Next ConsoleWrite("Selected parition, converting to letter..." & @CRLF) $sQuery = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $CurrentPartit & "'} WHERE AssocClass = Win32_LogicalDiskToPartition" $colLogicalDisks = $oWMISvc.ExecQuery($sQuery) For $oLogicalDisk In $colLogicalDisks $EndingDLetter = $oLogicalDisk.DeviceId Next ConsoleWrite("Drive letter is: " & $EndingDLetter & @CRLF)
    And the console output is:


    Selected right disk, selecting parition... Selected partition: Disk #0, Partition #0 Selected parition, converting to letter... Drive letter is: F:
×
×
  • Create New...