Sign in to follow this  
Followers 0
mdwerne

DriveGetDrive() does not return expected data...

4 posts in this topic

So I have a script that runs during the start up of a WinPE 3.1 device. The WinPE boot device may either be a USB Pen drive, or a CDRom. What my script is supposed to do is look for the attached drives and locate the first that is:

1) either "Removable" or "CDROM"

and

2) has one of two specific labels "Label1" or "Label2"

I've used the following functions for a number of years, but recently they stopped returning the expected drive letter and path. Upon closer inspection (_ArrayDisplay), the drive letter "C:" was being returned even though the "C:" drive is neither Removable nor a CDROM, and the C drive label does not match either of my conditions. If I remove the "C:" drive from the machine entirely, I still get "C:Data" returned?? Here are the two functions I run to find the correct drive and path, does anyone see something I'm obviously missing? Has DriveGetDrive changed in some way? Is there another way to do what I'm after that may work?

Again, this is all in a WinPE 3.1 X86 (sometimes X64) environment.

Thanks for any suggestions,

-Mike

Global $DataDrive = "", $ProgData

If $DataDrive = "" Then USB()
If $DataDrive = "" Then USB2()
If $DataDrive = "" Then CD()

If @OSArch = "X86" Then
    $ProgData = $DataDrive & "Data"
Else
    $ProgData = "X:\Program Files"
EndIf

    MsgBox(16, "ProgDataPath", $ProgData)

Func USB()
    $aDrives = DriveGetDrive("REMOVABLE")
    If @error = 1 Then Return
    For $i = 1 To UBound($aDrives) - 1
        If DriveGetLabel($aDrives[$i]) = "Label1" Then
            $DataDrive = $aDrives[$i] & "\"
            ExitLoop
        EndIf
    Next
EndFunc   ;==>USB

Func USB2()
    $aDrives = DriveGetDrive("REMOVABLE")
    If @error = 1 Then Return
    For $i = 1 To UBound($aDrives) - 1
        If DriveGetLabel($aDrives[$i]) = "Label2" Then
            $DataDrive = $aDrives[$i] & "\"
            ExitLoop
        EndIf
    Next
EndFunc   ;==>USB

Func CD()
    $aDrives = DriveGetDrive("CDROM")
    If @error = 1 Then Return
    For $i = 1 To UBound($aDrives) - 1
        If DriveGetLabel($aDrives[$i]) = "Label2" Then
            $DataDrive = $aDrives[$i] & "\"
            ExitLoop
        EndIf
    Next
EndFunc   ;==>CD

Share this post


Link to post
Share on other sites



can't help with your specific issue i'm afraid (will try next time i launch WinPE). but if you are trying to detect the drive where your AutoIt script is located, easier be extracted from:

@AutoItExe

Share this post


Link to post
Share on other sites

 

can't help with your specific issue i'm afraid (will try next time i launch WinPE). but if you are trying to detect the drive where your AutoIt script is located, easier be extracted from:

@AutoItExe

Thanks for the reply orbs, but unfortunatly no, my script is always located on the X: drive, the Data folder can vary by how many drives are already installed on the system. I'm currently playing with DriveGetStatus in case searching for only 'Ready' dirves helps.

-Mike

Share this post


Link to post
Share on other sites

So in case anyone comes across this post and has similar issues, this tidbit (found in the forums somewhere) seems to work.

Func NewWay()
    Local $myDrive
    Local $aDrives = DriveGetDrive('ALL')
    If IsArray($aDrives) Then
        For $sDrive In $aDrives
            If DriveStatus($sDrive) = 'READY' Then
                ; filter out drive types not wanted
                Switch DriveGetType($sDrive)
                    Case 'Network', 'FIXED', 'RAMDISK', 'Unknown'
                        ContinueLoop
                EndSwitch
                If DriveGetLabel($sDrive) = 'Label1' Then
                    $DataDrive = $sDrive & "\"
                    ExitLoop
                ElseIf DriveGetLabel($sDrive) = 'Label2' Then
                    $DataDrive = $sDrive & "\"
                    ExitLoop
                EndIf
            EndIf
        Next
    EndIf
EndFunc   ;==>NewWay

I'm still not sure why my other functions had been working for a few years, and then suddenly ceased to do so. Oh well.

-Mike

Share this post


Link to post
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
Sign in to follow this  
Followers 0