Jump to content
Sign in to follow this  

DriveGetDrive question

Recommended Posts

Hi, maybe is a silly question but i don't have understood how to make a list of internal HDD and external HDD-Pen Drive using DriveGetDrive

FIXED = Internal HDDs, right?

REMOVABLE = External HDDs - PenDrive, right?

How to get both in the same list? Thanks

Share this post

Link to post
Share on other sites

Use ALL.

UDF List:

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post

Link to post
Share on other sites

Use ALL.


that would return CDROM & NETWORK also, i think the OP is not interested in those.

i think that would require 2 calls to DriveGetDrive, and then concatenate the results.

but double-check your results: for some AHCI controllers, internal HDD may be classified as "REMOVABLE", and USB-connected SSD are usually classified "FIXED".

Share this post

Link to post
Share on other sites

With ALL i have CD-Rom/DVD, network drive and other thing i'm not intrested. I want only internal HDD and external HDD - Pen Drive in the same list but i want to know if an hdd is internal of external. Thanks

Share this post

Link to post
Share on other sites

You can use DriveGetType to choose drive types from the ALL types returned from DriveGetDrive.

; example 1 direct use
$drive = DriveGetDrive('ALL')
For $1 = 1 To UBound($drive) -1
    $type = DriveGetType($drive[$1])
    Switch $type
        Case 'FIXED', 'REMOVABLE'
            MsgBox(0x40, 'Test 1', 'YES  ' & $drive[$1] & '  ' & $type)
        Case Else
            MsgBox(0x30, 'Test 1', 'NO  ' & $drive[$1] & '  ' & $type)

; example 2 create new array
$drive = _DriveGetDriveByTypes('FIXED|REMOVABLE')
If IsArray($drive) Then
    For $1 In $drive
        MsgBox(0x40, 'Test 2', $1 & '  ' & DriveGetType($drive[$1]))

Func _DriveGetDriveByTypes($types = 'FIXED', $delimiter = '|')
    Local $1, $drive, $string
    If StringRegExp($delimiter, '[a-zA-Z:]') Then Return SetError(1, 0, 0)
    $types = $delimiter & $types & $delimiter
    $drive = DriveGetDrive('ALL')
    For $1 = 1 To UBound($drive) -1
        If StringInStr($types, $delimiter & DriveGetType($drive[$1]) & $delimiter) Then $string &= $drive[$1] & $delimiter
    $string = StringTrimRight($string, StringLen($delimiter))
    Return StringSplit($string, $delimiter, 3)

You can also choose the drives by using DriveGetLabel if you want certain labeled drive. Then there is DriveGetFileSystem and DriveGetSerial as well. :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kristo
      The DriveGetDrive command returned all drives (option "ALL") for years now and my program could always rely on that function. Suddenly a drive letter that was created with the subst command does not appear in the list of drives anymore. And it clearly did, because I used to react to a certain subst command by reacting to new or revoked (subst /D) drive letters.
      Why is that? I think this a bug because there's no way left to list ALL drive letters anymore.
      And why should I use an API command for that when this was already built in for years?

    • By johnmcloud
      Hi Guys,
      For work i need to know how which drive letter are avaiable and take the first.
      For now i have make this script:

      Local $aArray = DriveGetDrive("ALL") Local $avArray[24] $avArray[0] = "A:\" $avArray[1] = "B:\" $avArray[2] = "C:\" $avArray[3] = "D:\" $avArray[4] = "E:\" $avArray[5] = "F:\" $avArray[6] = "G:\" $avArray[7] = "H:\" $avArray[8] = "I:\" $avArray[9] = "J:\" $avArray[10] = "K:\" $avArray[11] = "L:\" $avArray[12] = "M:\" $avArray[13] = "N:\" $avArray[14] = "O:\" $avArray[15] = "P:\" $avArray[16] = "Q:\" $avArray[17] = "R:\" $avArray[18] = "S:\" $avArray[19] = "T:\" $avArray[20] = "U:\" $avArray[21] = "V:\" $avArray[22] = "X:\" $avArray[23] = "Y:\" $avArray[24] = "Z:\" If @error Then ; An error occurred when retrieving the drives. MsgBox(4096, "DriveGetDrive", "It appears an error occurred.") Else For $i = 1 To $aArray[0] ; Show all the drives found and convert the drive letter to uppercase. ConsoleWrite(StringUpper($aArray[$i]) & "\" & @CRLF) Next EndIf
      Hope is a good approach.

      The result of DriveGetDrive is:

      C:\ D:\ W:\ X:\ Y:\ Z:\
      So i want to compare mine letter with all avaible ( so the two array ), subtract from the complete list C-D-W-X-Y-Z and give me a new list, then take the fist drive avaiable ( in my case is E:\ = [1] )
      Some suggestion?

    • By hackersarchangel
      I have a project I'm working on, as part of a maintenance disk. I want to make a GUI for automating chkdsk startup, as in I run the GUI, then I select what drives I'm wanting to chkdsk. I want to run this from a PE based enviroment, I believe the disk I've chosen is a BartPE based disk, if that matters.

      Here's where my issue comes into play. When I start the program I have it set to specify a log save location with a Save As box. That part works great, so I have it make the GUI. Here's the issue: When I'm making the GUI, I want it to grab the drive letters and use that as part of either Checkboxes OR multiple dropdown menus. That part I'm flexible on, I just want it to work, and the dropdown menus was just another way of thinking about it.

      So I figured out how to grab drive letters into an array and do an If-Then for less than 4 drives (test machine has 3 drives, trying to get it work before worrying about whether or not it's less than 2 or 3):

      Global $Drives[5] = ["1","2","3","4","5"] $Drives = DriveGetDrive("Fixed") If $Drives[0] < 4 Then $Drives[4] = "None" EndIf

      For some reason, when I run that code, it flips it's lid about being outside my subscript range. I added the ReDim command to resize it back to 5, but that still doesn't work. Now if I set it when I initialize it, it's fine, and I can edit it all I want to manually, just not with DriveGetDrive.

      Current modified code:

      Global $Drives[5] = ["1","2","3","4","5"] $Drives = DriveGetDrive("Fixed") If $Drives[0] < 4 Then ReDim $Drives[5] $Drives[4] = "None" EndIf
      What I would like to do is resize the Array to fix the amount of drives I have, i.e. if I have 2 drives, make it 3 slots big, [0] for the count it generates, [1] for drive 1, [2] for drive 2, etc. and if it doesn't get a reply from slots 3 and 4, disable those checkboxes/remove the entry from the dropdown list. But that is further complicating the issue as it is, just want the basic premise to work.

      If anyone has any ideas for this little issue, I'm welcoming the ideas.
      Hey guys,

      I'm trying to use the delete files same time in Removable or change attrib to show.

      ex: delete : Autorun.inf ===> Attrib = SH in Removable

      this is try me :

      #cs ---------------------------------------------------------------------------- AutoIt Version: Author: GHOST SKIKDA Script Function: Hide Files System in Removable. #ce ---------------------------------------------------------------------------- #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GuiStatusBar.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 554, 454, 192, 114) GUISetBkColor(0x000000) $ListView1 = GUICtrlCreateListView("Name|Status", 16, 168, 522, 270, '', BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES)) _GUICtrlListView_SetExtendedListViewStyle(-1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 400) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x00FF00) GUICtrlSetBkColor(-1, 0x800000) $ListView1context = GUICtrlCreateContextMenu($ListView1) $MenuItem1 = GUICtrlCreateMenuItem("Show", $ListView1context) $MenuItem2 = GUICtrlCreateMenuItem("Hide", $ListView1context) $MenuItem3 = GUICtrlCreateMenuItem("Delete", $ListView1context) $Button1 = GUICtrlCreateButton("Scan", 462, 134, 75, 25, $WS_GROUP) $Combo1 = GUICtrlCreateCombo("", 50, 136, 409, 25) $Label1 = GUICtrlCreateLabel("Path : ", 16, 139, 35, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) Dim $StatusBar1_PartsWidth[1] = [-1] _GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth) _drivercombo() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _GUICtrlListView_DeleteAllItems($ListView1) Sleep(200) ;Search("f:\") _driver() Case $ListView1 EndSwitch WEnd ;~ Func _Search() ;~ $search = FileFindFirstFile("C:\*.*") ;~ If $search = -1 Then ;~ MsgBox(0, "Error", "No files/directories matched the search pattern") ;~ Exit ;~ EndIf ;~ $com=0 ;~ While 1 ;~ $file = FileFindNextFile($search) ;~ If @error Then ExitLoop ;~ $var = FileGetAttrib("C:\"&$file) ;~ If ($var = "RASH") or ($var = "SH") Then ;~ _GUICtrlListView_AddItem($ListView1, $file, $com) ;~ _GUICtrlListView_AddSubItem($ListView1, $com,$var, 1) ;~ ;_GUICtrlListView_SetItemChecked($ListView1, $com) ;~ $com=$com+1 ;~ EndIf ;~ WEnd ;~ FileClose($search) ;~ _GUICtrlStatusBar_SetText($StatusBar1, @TAB & "Resultat = " & _GUICtrlListView_GetItemCount($ListView1), 0) ;~ EndFunc Func Search($current) Local $search = FileFindFirstFile($current & "\*.*") $com=0 While 1 Dim $file = FileFindNextFile($search) If @error Or StringLen($file) < 1 Then ExitLoop $var = FileGetAttrib($current &"\"&$file) If ($var = "RASH") or ($var = "SH") or ($var = "RAH") or ($var = "ASH") Then;StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") and _GUICtrlListView_AddItem($ListView1, $file, $com) _GUICtrlListView_AddSubItem($ListView1, $com,$var, 1) ;_GUICtrlListView_SetItemChecked($ListView1, $com) $com=$com+1 Search($current & "\" & $file) EndIf Sleep (1) _GUICtrlStatusBar_SetText($StatusBar1, @TAB & "Resultat = " & _GUICtrlListView_GetItemCount($ListView1), 0) WEnd EndFunc Func _driver() $drv = DriveGetDrive( "Removable") If NOT @error Then For $i = 2 to $drv[0] GUICtrlSetData($Combo1,$drv[$i]) Search($drv[$i]) Next EndIf EndFunc Func _drivercombo() $drv = DriveGetDrive( "Removable") If NOT @error Then For $i = 2 to $drv[0] GUICtrlSetData($Combo1,$drv[$i]) Next EndIf EndFunc

  • Create New...