Jump to content

Start ONLY from Mass Storage?


Shocker
 Share

Recommended Posts

getdrives()

 Func getdrives()
; Fill the destination list
Local $drives = DriveGetDrive("ALL")
If @error == 1 Then
  MsgBox(0, "Error", "No removeable media found, cannot continue!" & @CRLF & "Please insert a micro SD card or other removeable media to copy to.", 15)
  ;GUISetState(@SW_SHOW, $mainwindow)
  GUISetState(@SW_HIDE, $cabswindow)
Else
  For $i = 1 To $drives[0]
   Local $drive = $i
   Local $type = DriveGetType($drives[$i] & "")
   If @error == 1 Then
    $type = "Error getting drive type"
   EndIf
   ConsoleWrite($drives[$i] & "\ " & $type & @CRLF)
  Next
EndIf
EndFunc   ;==>GetDrives

Result...

c: Fixed

d: Fixed

e: Fixed

f: CDROM

g: CDROM

h: Fixed -> is USB HDD

i: Removable -> is a USB Stick

Link to comment
Share on other sites

You can use a WMI query to find out if the device is an USB one or not.

Here is an example :

Local $aUSBDrives = _ListUSBVolumes()


Local $iRunFromUSB = 0
For $i = 1 To $aUSBDrives[0]
    If StringRegExp( @ScriptDir, "(?i)^" & $aUSBDrives[$i]) Then
        $iRunFromUSB = 1
        ExitLoop
    EndIf
Next

If $iRunFromUSB Then
    MsgBox(0, "", "OK")
Else
    MsgBox(16, "", "The program must be launched from an USB drive !")
EndIf
 
 
 
; #FUNCTION# ====================================================================================================================
; Name ..........: _ListUSBVolumes
; Description ...: List USB volumes
; Syntax ........: _ListUSBVolumes()
; Parameters ....: None
; Return values .: An array of strings (USB drive letter followed by colon) of drives found.
;                  The zeroth array element contains the number of drives.
; Author ........: jguinch
; ===============================================================================================================================
Func _ListUSBVolumes()
    Local $aResult[1]
 
    Local $oDrive, $sDeviceID, $oPartitions, $oPartition, $oLogicalDisks, $oLogicalDisk, $sDriveLetter
    Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
 
    Local $oDiskDrives = $oWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive Where InterfaceType = 'USB'")
 
    For $oDrive In $oDiskDrives
        $sDeviceID = StringReplace($oDrive.DeviceID, "\", "\\")
        $oPartitions = $oWMIService.ExecQuery _
            ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
                $sDeviceID & """} WHERE AssocClass = " & _
                    "Win32_DiskDriveToDiskPartition")
 
        For $oPartition In $oPartitions
            $oLogicalDisks = $oWMIService.ExecQuery _
                ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
                    $oPartition.DeviceID & """} WHERE AssocClass = " & _
                        "Win32_LogicalDiskToPartition")
 
            For $oLogicalDisk In $oLogicalDisks
                $sDriveLetter = $oLogicalDisk.DeviceID
                If $sDriveLetter <> "" Then
                    Redim $aResult[ UBound($aResult) + 1]
                    $aResult[ UBound($aResult) - 1] = $sDriveLetter
                EndIf
            Next
        Next
    Next
 
    $aResult[0] = UBound($aResult) - 1
    Return $aResult
EndFunc
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...