Jump to content
Sign in to follow this  
deviantp

Logical Partitions listed by Physical Disk

Recommended Posts

deviantp

Hey AutoIT forums!

I recently started a project in Batch to detect paritions and if configs are in a certain state, automatically partition the drive using disk part. The script works well, but with a few flaws involving drive size in bytes and batch no being able to handle numbers that large, so with recommendation from a friend I fired up AutoIT!

With batch I was using WMIC (LogicalDisk and DiskDrive) to get info, however there's no way of tying those two outcomes together, IE no common ground to reference what physical disk contains which partitions..

I'm very against being spoon fed code, so was wondering if anyone had any experience or ideas on how this could be done.

The ideal outcome would be add the active paritions on a physical disk into the 3d array I've constructed!

Any help much apprecaited

-Martin

Share this post


Link to post
Share on other sites
KaFu
mikell

Maybe the func used in this script can be helpful

#include <GUIConstantsEx.au3>
;#include <Array.au3>
#include <ListviewConstants.au3>

SplashTextOn ("", "Loading...", 180, 60, -1, -1, 49)
Global $var = DriveGetDrive("FIXED")
$myinfos = _GetDriveInfos()
;_arraydisplay($myinfos)

$W = 610
$Ypos = 45+(14*$var[0])
$Main = GuiCreate("Disques", $W+260, $Ypos)

$listview = GUICtrlCreateListView("Volume|Nom|Taille (Go)|Disponible (Go)|Occupé (Go)|" & _
"Plein à|Libre (Go)|Disque physique|ID", 10, 5, $W+240, $Ypos-15)
For $i = 0 to $var[0]-1
$percentocc = Round(($myinfos[$i][2]-$myinfos[$i][3])*100/$myinfos[$i][2], 1)
GUICtrlCreateListViewItem(StringUpper($myinfos[$i][0]) &"|"& $myinfos[$i][6] &"|"& _
$myinfos[$i][4] &"|"& $myinfos[$i][2] &"|"& $myinfos[$i][2]-$myinfos[$i][3] &"|"& _
$percentocc &" %" &"|"& $myinfos[$i][3] &"|"& $myinfos[$i][1] &"|"& $myinfos[$i][5], $listview)
Next
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 60)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 1, 110)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 2, 70)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 3, 90)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 4, 80)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 5, 70)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 6, 70)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 7, 170)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 8, 120)
GUISetState()

SplashOff()

While GUIGetMsg()<>$GUI_EVENT_CLOSE
Sleep(10)
WEnd

;======================================
Func _GetDriveInfos()
Dim $specifs[$var[0]][7]
For $i = 1 to $var[0]
Dim $Services = ObjGet('winmgmts:\\.\root\cimv2')
Dim $DiskDrives = $Services.ExecQuery("Select Caption, DeviceID From Win32_DiskDrive")
For $DiskDrive In $DiskDrives
Dim $DiskPartitions = $Services.ExecQuery("Associators of {Win32_DiskDrive.DeviceID='" & _
$DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition")
For $DiskPartition In $DiskPartitions
Dim $LogicalDisks = $Services.ExecQuery ("Associators of {Win32_DiskPartition.DeviceID='" & _
$DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
For $LogicalDisk In $LogicalDisks
If $LogicalDisk.DeviceID = $var[$i] Then
$specifs[$i-1][0] = $var[$i]
$specifs[$i-1][1] = $DiskDrive.Caption
$specifs[$i-1][2] = Round(DriveSpaceTotal($var[$i])/1000 )
$specifs[$i-1][3] = Round(DriveSpaceFree($var[$i])/1000 )
$specifs[$i-1][4] = Round($LogicalDisk.Size/1000000000)
$specifs[$i-1][5] = $DiskPartition.DeviceID
$specifs[$i-1][6] = $LogicalDisk.VolumeName
EndIf
Next
Next
Next
Next
Return $specifs
EndFunc
and the UDF scriptomatic.au3 to get more infos

Edited by mikell
  • Like 1

Share this post


Link to post
Share on other sites
deviantp

These are perfect! Thanks very much for your replies, I've done some adapting and have it all working as I need, thanks very much and am now convined AutoIT might get a lot more use in the near future!

Cheers guys!

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  

×