Jump to content

Finding CDROM drive letter


wisem2540
 Share

Recommended Posts

So I know there is a DRIVEGETDRIVE command to pull drive letters. But I have a unique situation.

I am attempting to automate the install of an application. I have successfully passed on switches to mount the ISO from a network location (After Installing Daemon Tools) Now I need to run the application

But the drive letter is not always the same. Am I able to qery the drive letter by volume label? (since the same Iso will alwyas be used)

Then maybe I can store it to a variable. ...or

Another option is that Daemon has a Get_Letter command, but it returns a number. Meaning 1=A, 2=B, 3=C and so on. So I could use the Daemon command, and if it returns 5, Autoit knows the drive letter should be E:

Which would be the easiest to accomplish?

Link to comment
Share on other sites

Local $type, $path

$path = "E:"
$type = DriveGetType($path)
If @error then
ConsoleWrite("No Drive Detected on path given." & @CRLF)
Else
ConsoleWrite("Drive Type: " & $type & @CRLF)
EndIf
$type = ""
$type = DriveGetFileSystem($path)
If @error then
ConsoleWrite("No Drive Detected on path given." & @CRLF)
Else
ConsoleWrite("Drive FileSystem: " & $type & @CRLF)
EndIf

If the File System reads "CDFS" then it's most likely a CD or an ISO. Once you confirm the drive is a CD/ISO, then you can check by label to determine if it's the correct "disk".

If you want to cut to the chase and check the label, check every drive until you match what you're looking for.

Local $x, $label, $drive, $match
$match = "LabelText"

For $x = 65 to 90
$drive = Chr($x) & ":"
$label = DriveGetLabel($drive)
If @error then ConsoleWrite("No drive found at position: " & $drive & @CRLF)
If $label = $match then
     ConsleWrite("Found it. Exiting Loop." & @CRLF)
     ExitLoop
Endif
Next

Packaged as a nifty little function for you:

$Drive = _FindDrive("LabelText")
If @error then ConsoleWrite("Error:  _FindDrive Failed to locate the label or you forgot to enter one to search for." & @CRLF)
Msgbox(0,"",$Drive)

Func _FindDrive($sMatch)
    If $sMatch = "" then Return 1
    Local $x, $sLabel, $sDrive
    For $x = 65 To 90
        $sDrive = Chr($x) & ":"
        $sLabel = DriveGetLabel($sDrive)
        If @error Then ConsoleWrite("No drive found at position: " & $drive & @CRLF)
        If $sLabel = $sMatch Then
            ConsleWrite("Found it at " & $sDrive & "  Exiting Loop." & @CRLF)
            Return $sDrive
        EndIf
    Next
    Return 1
EndFunc   ;==>_FindDrive
Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

You can also use DriveGetDrive ( "ALL" ) to return an array of all your drives to loop through, or just DriveGetDrive ( "CDROM" ) to return loaded ISO or CD drives

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...