Skip to content

Commit

Permalink
Merge pull request #23 from htcfreek/v1.3
Browse files Browse the repository at this point in the history
merge v1.3
  • Loading branch information
htcfreek authored Jul 5, 2021
2 parents ea6094c + 901a7a5 commit e423b65
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
74 changes: 38 additions & 36 deletions src/GetDiskInfoFromWmi/GetDiskInfoFromWmi.au3
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#cs
===============================================================================================================================
Title ...............: _GetDiskInfoFromWmi (GitHub: - https://github.com/htcfreek/AutoIt-Scripts)
Version .............: 1.3
Title ...............: _GetDiskInfoFromWmi (GitHub: https://github.com/htcfreek/AutoIt-Scripts)
Version .............: 1.4
License .............: GNU LGPLv3
AutoIt Version ......: 3.3.14.5+
Language ............: English
Expand All @@ -20,24 +20,27 @@
===============================================================================================================================
CHANGELOG:
2021-07-05 (v1.4)
Fix: Typos in script and example.
2021-07-04 (v1.3)
Fixed: Typos
Changed: Improved comments
Changed: Disk property header renamed: WindowsRunningOnDisk (SystemRoot) -> WindowsRunningOnDisk (SystemDisk)
Changed: Partition property header renamed: PartitionIsSystemRoot -> PartitionIsSystemDisk
Add: DiskType filter
Add: Constants
Add: Required includes
Add: Error handling
Fix: Typos
Change: Improved comments
Change: Disk property header renamed: WindowsRunningOnDisk (SystemRoot) -> WindowsRunningOnDisk (SystemDisk)
Change: Partition property header renamed: PartitionIsSystemRoot -> PartitionIsSystemDisk
New: DiskType filter
New: Constants
New: Required includes
New: Error handling
2021-07-02 (v1.2)
Added: Disk properties Manufacturer, Interfacetype, Mediatype, Serialnumber, Status
Added: Partition property: Filesystem
Changed: Disk property header renamed: SystemIsBootedFromDisk -> WindowsRunningOnDisk (SystemRoot)
Changed: Partition property header renamed: SystemIsBootedFromPartition -> PartitionIsSystemRoot
New: Disk properties Manufacturer, InterfaceType, MediaType, SerialNumber, Status
New: Partition property: Filesystem
Change: Disk property header renamed: SystemIsBootedFromDisk -> WindowsRunningOnDisk (SystemRoot)
Change: Partition property header renamed: SystemIsBootedFromPartition -> PartitionIsSystemRoot
2021-07-02 (v1.0)
Initial release
New: Initial release
#ce

Expand All @@ -57,27 +60,26 @@ Global Const $DiskInfoWmi_DiskType_Unknown = "Unknown%"

; Function
; ---------

Func _GetDiskInfoFromWmi(ByRef $aDiskList, ByRef $aPartitionList, $bAddTableHeader = $DiskInfoWmi_TableHeader_Yes, $sFilterDiskType = $DiskInfoWmi_DiskType_All)
; Name ...............: _GetDiskInfoFromWmi
; Name ...............: _GetDiskInfoFromWmi
; Author .............: htcfreek (Heiko) - https://github.com/htcfreek
; Input parameter ....: ByRef $aDiskList = Array var for list of disks.
; Input parameter ....: ByRef $aDiskList = Array var for list of disks.
; ByRef $aPartitionList = Array var for list of partitions.
; [$bAddTableHeader = $DiskInfoWmi_TableHeader_Yes] = Should array tables have a header row. (Values: 0|1 or $DiskInfoWmi_TableHeader_Yes|$DiskInfoWmi_TableHeader_No)
; [$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)
; Output parameter ...: none
; Output parameter ...: none
; On WMI-Error .......: @error = 1


; Initialize function wide vars
Local $aDisks[0][12]
Local $aPartitions[0][13]
Local $iDiskArrayCount = 0 ; Initialize counter to write some disk data later in correct array row.
Local $iPartArrayCount = 0 ; Initialize counter to write partition data later in correct array row.
Local $iDiskArrayCount = 0 ; Initialize counter to write some disk data later in correct array row.
Local $iPartArrayCount = 0 ; Initialize counter to write partition data later in correct array row.



; Add Array header
if ($bAddTableHeader = 1) Then
if ($bAddTableHeader = 1) Then
$sDiskHeader = "DiskNum" & "||" & "DiskDeviceID" & "||" & "DiskManufacturer" & "||" & "DiskModel" & "||" & "DiskInterfaceType" & "||" & "DiskMediaType" & "||" & "DiskSerialNumber" & "||" & "DiskState" & "||" & "DiskSize" & "||" & "DiskInitType" & "||" & "DiskPartitionCount" & "||" & "WindowsRunningOnDisk (SystemDrive)"
_ArrayAdd($aDisks, $sDiskHeader, 0, "||")
$sPartitionHeader = "DiskNum" & "||" & "PartitionNum" & "||" & "PartitionID" & "||" & "PartitionType" & "||" & "PartitionIsPrimary" & "||" & "PartitionIsBootPartition" & "||" & "PartitionLetter" & "||" & "PartitionLabel" & "||" & "PartitionFileSystem" & "||" & "PartitionSizeTotal" & "||" & "PartitionSizeUsed" & "||" & "PartitionSizeFree" & "||" & "PartitionIsSystemDrive"
Expand All @@ -96,22 +98,22 @@ Func _GetDiskInfoFromWmi(ByRef $aDiskList, ByRef $aPartitionList, $bAddTableHead
Local $iDisk = $oDisk.Index
Local $sNewDisk = $iDisk & "||" & $oDisk.DeviceID & "||" & $oDisk.Manufacturer & "||" & $oDisk.Model & "||" & $oDisk.InterfaceType & "||" & $oDisk.MediaType & "||" & $oDisk.SerialNumber & "||" & $oDisk.Status & "||" & $oDisk.Size & "||" & "<DiskInitStyle>" & "||" & $oDisk.Partitions & "||" & False
_ArrayAdd($aDisks, $sNewDisk, 0, "||")

; Get Partitions
Local $oPartitions = $oWmiInstance.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $oDisk.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
For $oPartition In $oPartitions
; Add Partition data to Array
Local $iPartition = $oPartition.Index
Local $sNewPart = $iDisk & "||" & $iPartition & "||" & $oPartition.DeviceID & "||" & $oPartition.Type & "||" & $oPartition.PrimaryPartition & "||" & $oPartition.BootPartition & "||" & "" & "||" & "" & "||" & "" & "||" & $oPartition.Size & "||" & "" & "||" & "" & "||" & False
_ArrayAdd($aPartitions, $sNewPart, 0, "||")

; Set DiskInitStyle
if StringRegExp ( $oPartition.Type, "^GPT.*") Then
if StringRegExp($oPartition.Type, "^GPT.*") Then
$aDisks[$iDiskArrayCount][9] = "GPT"
Else
Else
$aDisks[$iDiskArrayCount][9] = "MBR"
EndIf

; Get logical disks
Local $oLogicalDisks = $oWmiInstance.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $oPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
For $oLogicalDisk In $oLogicalDisks
Expand All @@ -122,27 +124,27 @@ Func _GetDiskInfoFromWmi(ByRef $aDiskList, ByRef $aPartitionList, $bAddTableHead
$aPartitions[$iPartArrayCount][9] = $oLogicalDisk.Size ; Value of LogicalDisk.Size is different to Size of DiskPartition.Size!!
$aPartitions[$iPartArrayCount][10] = ($oLogicalDisk.Size - $oLogicalDisk.FreeSpace)
$aPartitions[$iPartArrayCount][11] = $oLogicalDisk.FreeSpace
; Detect SystemBootDisk

; Detect SystemBootDisk
if $oLogicalDisk.DeviceID = EnvGet("SystemDrive") Then
$aDisks[$iDiskArrayCount][11] = True
$aPartitions[$iPartArrayCount][12] = True
EndIf
Next

; Array counter (Partitions) + 1
$iPartArrayCount += 1
Next

; Array counter (Disks) + 1
$iDiskArrayCount += 1
Next
Else
; If WMI-Error then set @error
SetError(1)
EndIf

; Return Data
$aDiskList = $aDisks
$aPartitionList = $aPartitions
$aPartitionList = $aPartitions
EndFunc ;==>_GetDiskInfoFromWmi
4 changes: 2 additions & 2 deletions src/GetDiskInfoFromWmi/UsageExample.au3
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Local $aOutputDisks
Local $aOutputPartitions
_GetDiskInfoFromWmi($aOutputDisks, $aOutputPartitions, $DiskInfoWmi_TableHeader_Yes, $DiskInfoWmi_DiskType_Fixed)
If @error Then MSGBOX(16, @ScriptName, "Something goes wrong!")
If @error Then MSGBOX(16, @ScriptName, "Something went wrong!")

_ArrayDisplay($aOutputDisks, "Disks")
_ArrayDisplay($aOutputPartitions, "Partitions")
_ArrayDisplay($aOutputPartitions, "Partitions")

0 comments on commit e423b65

Please sign in to comment.