Jump to content

Recommended Posts

Posted

HI,

I would like to know if anyone has already tried to create a script that runs the .exex program from a flash drive so that the script does not pay attention to the drive letter but the name of the flash drive? 

Posted

Probably a little overdone as an answer to your question :lol:.

#AutoIt3Wrapper_UseUpx=n
#include <Array.au3>  ; *** just for display

Opt("MustDeclareVars", 1)

Global $g_oCOMError      = ObjEvent("AutoIt.Error", "_COMError") ; custom error handler
Global $g_IP             = "localhost"
Global $g_objWMIService  = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $g_IP & "\root\cimv2")
Global $g_aMyDriveLabels = _GetWMIDriveinfo()
Global $sSearchLabel
_ArrayDisplay($g_aMyDriveLabels, "Drive Infos : ", default, default, default, "Letter|VolName|DriveType|FileSystem")

$sSearchLabel = "Label_you_are_looking_for"
Global $g_iIndex = _ArraySearch($g_aMyDriveLabels, $sSearchLabel)
If @error Then
    ConsoleWrite("! ERROR : Label : <" & $sSearchLabel & "> not found" & @CRLF)
Else
    ConsoleWrite("> Index Label : <" & $sSearchLabel & "> = " & $g_iIndex & @CRLF)
    ConsoleWrite("+ DriveLetter : <" & $g_aMyDriveLabels[$g_iIndex][0] & ">" & @CRLF)
EndIf

; ----------------------------------------------------------------
Func _GetWMIDriveinfo()
    Local $DriveLabel, $sDriveLabels, $i
    Local $aDriveLabels[26][4]
    Local $sDriveType

    ; see : https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-logicaldisk
    Local $colItems = $g_objWMIService.ExecQuery("SELECT Name, VolumeName, DriveType, FileSystem FROM Win32_LogicalDisk", "WQL", 0x30)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $aDriveLabels[$i][0] = $objItem.Name
            $aDriveLabels[$i][1] = $objItem.VolumeName

            Switch $objItem.DriveType
                Case 0
                    $sDriveType = "Unknown"
                Case 1
                    $sDriveType = "No Root Directory"
                Case 2
                    $sDriveType = "Removable Disk"
                Case 3
                    $sDriveType = "Local Disk"
                Case 4
                    $sDriveType = "Network Drive"
                Case 5
                    $sDriveType = "Compact Disc"
                Case 6
                    $sDriveType = "RAM Disk"
                Case Else
                    $sDriveType = "???"
            EndSwitch
            $aDriveLabels[$i][2] = $sDriveType

            $aDriveLabels[$i][3] = $objItem.FileSystem


            $i += 1
        Next
    EndIf
    ReDim $aDriveLabels[$i][4]
    Return $aDriveLabels
EndFunc

; ----------------------------------------------------------------
Func _COMError()
  Msgbox(0,"AutoIt : COM Error","COM Error occurred !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $g_oCOMError.Description    & @CRLF & _
             "err.windescription:"     & @TAB & $g_oCOMError.WinDescription & @CRLF & _
             "err.number is: "         & @TAB & Hex($g_oCOMError.Number, 8) & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $g_oCOMError.LastDllError   & @CRLF & _
             "err.scriptline is: "     & @TAB & $g_oCOMError.Scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $g_oCOMError.Source _
            )
EndFunc

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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...