Jump to content

Getting all partitions connected to a computer


Recommended Posts

Hi all,

i need a way to get a list of all partitions of all drives connected to a computer. Even those that do not have a driveletter (like the one that windows 7 creates for its bootfiles)...

They should be named HD1:1, HD1:2, HD2:1....and so on...

Can anyone give me an idea how i can get this?

Thanks!

Link to comment
Share on other sites

Maybe this will give you some idea?

#AutoIt3Wrapper_UseX64=N
#include <Array.au3>

Global $aExample

$aExample = _GetDriveDetails()
_ArrayDisplay($aExample)

Func _GetDriveDetails()
    Local $aReturn[26 + 1][10] = [[0, 9]], $oColItems, $oWMIService, $sData, $sUnknown

    $sUnknown = "(Unknown)"
    $aGetDrives = _DriveGetDrive(0)
    For $A = 1 To $aGetDrives[0]
        $aReturn[0][0] += 1
        For $B = 1 To $aReturn[0][1] - 5
            $aReturn[$A][$B] = $sUnknown ; Fill the first 4 columns with Unknown.
        Next
        $aReturn[$A][0] = StringUpper(StringLeft($aGetDrives[$A], 1))
        $aReturn[$A][3] = _RandomText(10)
    Next

    $oWMIService = ObjGet("winmgmts:localhost")
    $oColItems = $oWMIService.ExecQuery("Select * From Win32_LogicalDiskToPartition", "WQL", 0x30)

    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            $sData = _StringBetweenEx($oObjectItem.Dependent, 'Win32_LogicalDisk.DeviceID="', ':"')
            For $A = 1 To $aReturn[0][0]
                If $sData = $aReturn[$A][0] Then
                    $aReturn[$A][1] = _StringBetweenEx($oObjectItem.Antecedent, 'Win32_DiskPartition.DeviceID="', '"')
                    $aStringSplit = StringSplit($aReturn[$A][1], ",", 2)
                    $aReturn[$A][1] = $aStringSplit[0]
                    $aReturn[$A][2] = $aStringSplit[1]
                    ExitLoop
                EndIf
            Next
        Next
    EndIf
    $oColItems = $oWMIService.ExecQuery("Select * From Win32_DiskDriveToDiskPartition", "WQL", 0x30)
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            $sData = _StringBetweenEx($oObjectItem.Dependent, 'Win32_DiskPartition.DeviceID="', '"')
            For $A = 1 To $aReturn[0][0]
                If $sData = $aReturn[$A][1] & "," & $aReturn[$A][2] Then
                    $aReturn[$A][3] = StringReplace(_StringBetweenEx($oObjectItem.Antecedent, 'Win32_DiskDrive.DeviceID="', '"'), ".", ".")
                EndIf
            Next
        Next
    EndIf
    $oColItems = $oWMIService.ExecQuery("Select * From Win32_DiskDrive", "WQL", 0x30)
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            For $A = 1 To $aReturn[0][0]
                If $oObjectItem.DeviceID = $aReturn[$A][3] Then
                    $aReturn[$A][4] = $oObjectItem.Model
                    $aReturn[$A][5] = $oObjectItem.InterfaceType
                    $aReturn[$A][6] = $oObjectItem.PNPDeviceID
                    $aReturn[$A][7] = $oObjectItem.Partitions
                EndIf
            Next
        Next
    EndIf

    For $A = 1 To $aReturn[0][0] ; Find Drive Partitions.
        For $B = 1 To $aReturn[0][0]
            If $aReturn[$A][3] = $aReturn[$B][3] Then
                $aReturn[$B][8] &= $aReturn[$A][0] & "|"
            EndIf
        Next
    Next
    For $A = 1 To $aReturn[0][0] ; Trim '|' From The End Of The Drive Partitions.
        $aReturn[$A][3] = $sUnknown
        $aReturn[$A][8] = StringTrimRight($aReturn[$A][8], 1)
    Next

    ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]]
    Return $aReturn
EndFunc   ;==>_GetDriveDetails

Func _DriveGetDrive($iDriveType)
    Local $aArray
    Switch $iDriveType
        Case -1, 0
            $iDriveType = "ALL"
        Case 1
            $iDriveType = "FIXED"
        Case 2
            $iDriveType = "REMOVABLE"
    EndSwitch

    $aArray = DriveGetDrive($iDriveType)
    If @error Then
        Return SetError(1, 0, 0)
    EndIf
    Return $aArray
EndFunc   ;==>_DriveGetDrive

Func _RandomText($iLength = 10)
    Local $sData = "", $sRandom
    For $A = 1 To $iLength
        $sRandom = Random(55, 116, 1)
        $sData &= Chr($sRandom + 6 * ($sRandom > 90) - 7 * ($sRandom < 65))
    Next
    Return $sData
EndFunc   ;==>_RandomText

Func _StringBetweenEx($sString, $sStart, $sEnd)
    Local $aReturn
    If $sStart = "" Then
        $sStart = "A"
    EndIf
    If $sEnd = "" Then
        $sEnd = "z"
    EndIf
    $aReturn = StringRegExp($sString, '(?s)(?i)' & $sStart & '(.*?)' & $sEnd, 3)
    If @error Then
        Return $sString
    EndIf
    If $aReturn[0] = "" Then
        Return $sString
    EndIf
    Return $aReturn[0]
EndFunc   ;==>_StringBetweenEx

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

Link to comment
Share on other sites

Thanks a lot, but it does not show partitions without drive letters....and those are my main problem:-)

Edit: the code is quite interresting, maybe i can work something out based on it....any easy idea is still welcome.-)

Edited by Allow2010
Link to comment
Share on other sites

Thanks a lot, but it does not show partitions without drive letters....and those are my main problem:-)

I knew it wasn't what you were looking for but what you are asking just doesn't sound feasible to me.

Edit: the code is quite interresting, maybe i can work something out based on it....any easy idea is still welcome.-)

I'm glad. Edited by guinness

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

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