This example searches for active removable drives butit can be set to any type of drive by setting Let>TypeOfDrive= to any of the listed drive types.
Tested on Windows XP SP2
Written with version 10.1.15
Script Discussion Here
Code: Select all
/*
Drive types
: Unknown
: Removable
: Fixed
: Network
: CD-ROM
: RAM
*/
//Set type of active drives you want to search for
Let>TypeOfDrive=: Removable
//Get list of all available Drives
VBSTART
Option Explicit
' Drive type constants
Function GetDrives
Const Unknown = 0 'Unknown
Const Removable = 1 ' Removable
Const Fixed = 2 ' Fixed medium (hard disk)
Const Remote = 3 ' Network drive
Const CDROM = 4 ' CD-ROM
Const RAMDisk = 5 ' RAM disk
Dim Text, Title
Dim fso, oDrive, curDrive ' Object variables
Dim drtype(6)
drtype(0) = ": Unknown"
drtype(1) = ": Removable"
drtype(2) = ": Fixed"
drtype(3) = ": Network"
drtype(4) = ": CD-ROM"
drtype(5) = ": RAM"
Set fso = CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.Drives ' Get Drives collection.
For Each curDrive In oDrive ' All drive objects
Text = Text & curDrive.DriveLetter' Drive letter
Text = Text & drtype(curDrive.DriveType)
Text = Text & vbCrLf
Next
GetDrives = Text
End Function
VBEND
VBEval>GetDrives,DriveInfo
MessageModal>DriveInfo
Separate>DriveInfo,CRLF,Lines
Let>DRIVE_LIST=
Let>Kline=0
Let>TotalActiveDrives=0
label>Get Drives List
Add>Kline,1
Let>CurrentLine=Lines_%Kline%
//Check if drive is removable
Separate>%CurrentLine%,%TypeOfDrive%,var
//If var count equals 2 drive is removable
if>%var_count%=2
//Set list of removable drives
StringReplace>CurrentLine,%TypeOfDrive%,,DRIVE_LETTER
ConCat>DRIVE_LIST,%DRIVE_LETTER%
Add>TotalActiveDrives,1
endif
if>%var_count%=0,Drives Result
goto>Get Drives List
label>Drives Result
MessageModal>Available Drives: %DRIVE_LIST%
Let>SourceString=%DRIVE_LIST%
Let>DriveList=
Let>KK=0
Repeat>KK
Let>KK=KK+1
MidStr>SourceString,KK,1,DriveLetter
//Check if Removable Drive is active
IfFileExists>%DriveLetter%:\NUL
//Set Active Drives
ConCat>DriveList,%DriveLetter%%CRLF%
endif
Until>KK=%TotalActiveDrives%
MessageModal>Active Drives%CRLF%%DriveList%