Jump to content

Recommended Posts

Posted

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
Posted

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

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Posted

 

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

Posted

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

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
  • Recently Browsing   0 members

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