1- ; GetDiskInfoFromWmi.au3
2-
3- Func _GetDiskInfoFromWmi(ByRef $aDiskList , ByRef $aPrtitionList , $bAddTableHeader = 1 )
4- ; Name: _GetDiskInfoFromWmi (GitHub: - https://github.com/htcfreek/AutoIt-Scripts)
5- ; Author: htcfreek (Heiko) - https://github.com/htcfreek
6- ; Version: 1.2
7- ; License: GNU LGPLv3
8- ; Input parameter: ByRef $aDiskList = Array var for list of disks.; ByRef $aPrtitionList = Array var for list of partitions.; [$bAddTableHeader = 1] = Should array tables have a header rows.
9- ; Output parameter: none
10- ; Required includes: <Array.au3>
11-
1+ ; Includes
2+ ; ----------
3+ #include-once
4+ #include < Array.au3>
5+
6+
7+
8+ #cs
9+ ===============================================================================================================================
10+ Title ...............: _GetDiskInfoFromWmi (GitHub: - https://github.com/htcfreek/AutoIt-Scripts)
11+ Version .............: 1.3
12+ License .............: GNU LGPLv3
13+ AutoIt Version ......: 3.3.14.5+
14+ Language ............: English
15+ Description .........: Get disk and partition informations from WMI.
16+ Author ..............: htcfreek (Heiko) - https://github.com/htcfreek [original]
17+ Modified ............:
18+ Required includes ...: Array.au3
19+ Dll .................:
20+ ===============================================================================================================================
21+
22+ CHANGELOG:
23+ 2021-07-04 (v1.3)
24+ Fixed: Typos
25+ Changed: Improved comments
26+ Changed: Disk property header renamed: WindowsRunningOnDisk (SystemRoot) -> WindowsRunningOnDisk (SystemDisk)
27+ Changed: Partition property header renamed: PartitionIsSystemRoot -> PartitionIsSystemDisk
28+ Add: Constants
29+ Add: Required includes
30+ Add: Error handling
31+
32+ 2021-07-02 (v1.2)
33+ Added: Disk properties Manufacturer, Interfacetype, Mediatype, Serialnumber, Status
34+ Added: Partition property: Filesystem
35+ Changed: Disk property header renamed: SystemIsBootedFromDisk -> WindowsRunningOnDisk (SystemRoot)
36+ Changed: Partition property header renamed: SystemIsBootedFromPartition -> PartitionIsSystemRoot
37+
38+ 2021-07-02 (v1.0)
39+ Initial release
40+
41+ #ce
42+
43+
44+
45+ ; Global constants
46+ ; -----------------
47+ Global Const $DiskInfoWmi_TableHeader_Yes = 1
48+ Global Const $DiskInfoWmi_TableHeader_No = 0
49+ Global Const $DiskInfoWmi_DiskType_All = " %"
50+ Global Const $DiskInfoWmi_DiskType_External = " External%"
51+ Global Const $DiskInfoWmi_DiskType_Removable = " Removable%"
52+ Global Const $DiskInfoWmi_DiskType_Fixed = " Fixed%"
53+ Global Const $DiskInfoWmi_DiskType_Unknown = " Unknown%"
54+
55+
56+
57+ ; Function
58+ ; ---------
59+
60+ Func _GetDiskInfoFromWmi(ByRef $aDiskList , ByRef $aPartitionList , $bAddTableHeader = $DiskInfoWmi_TableHeader_Yes , $sFilterDiskType = $DiskInfoWmi_DiskType_All )
61+ ; Name ...............: _GetDiskInfoFromWmi
62+ ; Author .............: htcfreek (Heiko) - https://github.com/htcfreek
63+ ; Input parameter ....: ByRef $aDiskList = Array var for list of disks.
64+ ; ByRef $aPrtitionList = Array var for list of partitions.
65+ ; [$bAddTableHeader = $DiskInfoWmi_TableHeader_Yes] = Should array tables have a header row. (Values: 0|1 or $DiskInfoWmi_TableHeader_Yes|$DiskInfoWmi_TableHeader_No)
66+ ; [$sFilterDiskType = $DiskInfoWmi_DiskType_All] = Which type of disk should be included in result. (Values: $DiskInfoWmi_DiskType_All|$DiskInfoWmi_DiskType_External|$DiskInfoWmi_DiskType_Removable|$DiskInfoWmi_DiskType_Fixed|$DiskInfoWmi_DiskType_Unknown)
67+ ; Output parameter ...: none
68+ ; On WMI-Error .......: @error = 1
69+
1270
1371 ; Initialize function wide vars
1472 Local $aDisks [0 ][12 ]
@@ -19,9 +77,9 @@ Func _GetDiskInfoFromWmi(ByRef $aDiskList, ByRef $aPrtitionList, $bAddTableHeade
1977
2078 ; Add Array header
2179 if ($bAddTableHeader = 1 ) Then
22- $sDiskHeader = " DiskNum" & " ||" & " DiskDeviceID" & " ||" & " DiskManufacturer" & " ||" & " DiskModel" & " ||" & " DiskInterfacetype " & " ||" & " DiskMediatype " & " ||" & " DiskSerialnumber " & " ||" & " DiskState" & " ||" & " DiskSize" & " ||" & " DiskInitType" & " ||" & " DiskPartitionCount" & " ||" & " WindowsRunningOnDisk (SystemRoot )"
80+ $sDiskHeader = " DiskNum" & " ||" & " DiskDeviceID" & " ||" & " DiskManufacturer" & " ||" & " DiskModel" & " ||" & " DiskInterfaceType " & " ||" & " DiskMediaType " & " ||" & " DiskSerialNumber " & " ||" & " DiskState" & " ||" & " DiskSize" & " ||" & " DiskInitType" & " ||" & " DiskPartitionCount" & " ||" & " WindowsRunningOnDisk (SystemDrive )"
2381 _ArrayAdd($aDisks , $sDiskHeader , 0 , " ||" )
24- $sPartitionHeader = " DiskNum" & " ||" & " PartitionNum" & " ||" & " PartitionID" & " ||" & " PartitionType" & " ||" & " PartitionIsPrimary" & " ||" & " PartIsBootPartition " & " ||" & " PartitionLetter" & " ||" & " PartitionLabel" & " ||" & " PartitionFilesystem " & " ||" & " PartitionSizeTotal" & " ||" & " PartitionSizeUsed" & " ||" & " PartitionSizeFree" & " ||" & " PartitionIsSystemRoot "
82+ $sPartitionHeader = " DiskNum" & " ||" & " PartitionNum" & " ||" & " PartitionID" & " ||" & " PartitionType" & " ||" & " PartitionIsPrimary" & " ||" & " PartitionIsBootPartition " & " ||" & " PartitionLetter" & " ||" & " PartitionLabel" & " ||" & " PartitionFileSystem " & " ||" & " PartitionSizeTotal" & " ||" & " PartitionSizeUsed" & " ||" & " PartitionSizeFree" & " ||" & " PartitionIsSystemDrive "
2583 _ArrayAdd($aPartitions , $sPartitionHeader , 0 , " ||" )
2684 $iDiskArrayCount += 1
2785 $iPartArrayCount += 1
@@ -31,11 +89,11 @@ Func _GetDiskInfoFromWmi(ByRef $aDiskList, ByRef $aPrtitionList, $bAddTableHeade
3189 Local $oWmiInstance = ObjGet (' winmgmts:\\' & @ComputerName & ' \root\cimv2' )
3290 If (IsObj ($oWmiInstance )) And (Not @error ) Then
3391 ; Get Disks
34- Local $oPhysicalDisks = $oWmiInstance .ExecQuery(' Select * from Win32_DiskDrive' )
92+ Local $oPhysicalDisks = $oWmiInstance .ExecQuery(' Select * from Win32_DiskDrive WHERE MediaType like " ' & $sFilterDiskType & ' " ' )
3593 For $oDisk In $oPhysicalDisks
3694 ; Add Disk data to Array
3795 Local $iDisk = $oDisk .Index
38- Local $sNewDisk = $iDisk & " ||" & $oDisk .DeviceID & " ||" & $oDisk .Manufacturer & " ||" & $oDisk .Model & " ||" & $oDisk .Interfacetype & " ||" & $oDisk .Mediatype & " ||" & $oDisk .Serialnumber & " ||" & $oDisk .Status & " ||" & $oDisk .Size & " ||" & " <DiskInitStyle>" & " ||" & $oDisk .Partitions & " ||" & False
96+ Local $sNewDisk = $iDisk & " ||" & $oDisk .DeviceID & " ||" & $oDisk .Manufacturer & " ||" & $oDisk .Model & " ||" & $oDisk .InterfaceType & " ||" & $oDisk .MediaType & " ||" & $oDisk .SerialNumber & " ||" & $oDisk .Status & " ||" & $oDisk .Size & " ||" & " <DiskInitStyle>" & " ||" & $oDisk .Partitions & " ||" & False
3997 _ArrayAdd($aDisks , $sNewDisk , 0 , " ||" )
4098
4199 ; Get Partitions
@@ -53,34 +111,37 @@ Func _GetDiskInfoFromWmi(ByRef $aDiskList, ByRef $aPrtitionList, $bAddTableHeade
53111 $aDisks [$iDiskArrayCount ][9 ] = " MBR"
54112 EndIf
55113
56- ; Get LogicalDiks
114+ ; Get logical disks
57115 Local $oLogicalDisks = $oWmiInstance .ExecQuery(" ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $oPartition .DeviceID & " '} WHERE AssocClass = Win32_LogicalDiskToPartition" )
58116 For $oLogicalDisk In $oLogicalDisks
59117 ; Add logical disk data to array
60118 $aPartitions [$iPartArrayCount ][6 ] = $oLogicalDisk .DeviceID
61119 $aPartitions [$iPartArrayCount ][7 ] = $oLogicalDisk .VolumeName
62- $aPartitions [$iPartArrayCount ][8 ] = $oLogicalDisk .Filesystem
63- $aPartitions [$iPartArrayCount ][9 ] = $oLogicalDisk .Size ; Value of LogicalDisk.Size is different to Size of DiskPartiton .Size!!
120+ $aPartitions [$iPartArrayCount ][8 ] = $oLogicalDisk .FileSystem
121+ $aPartitions [$iPartArrayCount ][9 ] = $oLogicalDisk .Size ; Value of LogicalDisk.Size is different to Size of DiskPartition .Size!!
64122 $aPartitions [$iPartArrayCount ][10 ] = ($oLogicalDisk .Size - $oLogicalDisk .FreeSpace)
65123 $aPartitions [$iPartArrayCount ][11 ] = $oLogicalDisk .FreeSpace
66124
67125 ; Detect SystemBootDisk
68- if $oLogicalDisk .DeviceID = Envget (" SystemDrive" ) Then
126+ if $oLogicalDisk .DeviceID = EnvGet (" SystemDrive" ) Then
69127 $aDisks [$iDiskArrayCount ][11 ] = True
70128 $aPartitions [$iPartArrayCount ][12 ] = True
71129 EndIf
72130 Next
73131
74- ; ArrayCounter + 1
132+ ; Array counter (Partitions) + 1
75133 $iPartArrayCount += 1
76134 Next
77135
78- ; ArrayCounter + 1
136+ ; Array counter (Disks) + 1
79137 $iDiskArrayCount += 1
80138 Next
139+ Else
140+ ; If WMI-Error then set @error
141+ SetError (1 )
81142 EndIf
82143
83144 ; Return Data
84145 $aDiskList = $aDisks
85- $aPrtitionList = $aPartitions
146+ $aPartitionList = $aPartitions
86147EndFunc ; ==>_GetDiskInfoFromWmi
0 commit comments