Jump to content

DriveInfo - including drive/USB model e.t.c.


Muzaiyan
 Share

Recommended Posts

Hi, Hello, Salam

I am new here and this is my first post ever here.

This is a simple script which gives you information about drive including drive model/vendor.

Any help, upgrade or change is appreciated. :)

 

include this:

; #INDEX# =======================================================================================================================
; Title .........: DriveInfo
; AutoIt Version : 3.3.10.2
; Language ......: English
; Description ...: Returns Drive info,including drive model, PNP Device ID e.t.c.
; Author(s) .....: Muzaiyan Abbas,1 Unknown
; ===============================================================================================================================

#cs
; #FUNCTION# ====================================================================================================================
; Name ..........: _Drives_Determine
; Description ...:
; Syntax ........: _Drives_Determine()
; Parameters ....:
; Return values .: an array

The number of drives returned will be in $s_Array[0][0]

$s_Array[0][0] = Total Number of Drives.
$s_Array[1][0] = 1st drive letter
$s_Array[1][1] = 1st drive vendor/model
$s_Array[1][2] = Is Primary (True OR False)
$s_Array[1][3] = File System
$s_Array[1][4] = PNP Device ID
$s_Array[1][5] = Caption
(in the most inner loop (model = caption) becomes true.)

; Author ........: Muzaiyan Abbas
; Original Author ........: (Unknows)
; Modified ......: Yes
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
#ce
Func _Drives_Determine()
    Local $Columns = 7 ; if total drives are known
    Local $Number_DRV = DriveGetDrive('ALL')
    $Columns = $Number_DRV[0]
    Local $Drives[($Number_DRV[0] + 1)][$Columns]
    $Drives[0][0] = -1
    Local $strdeviceid, $colpartitions, $collogicaldisks
    Dim $Obj_WMIService = ObjGet('winmgmts:\\' & "." & '\root\cimv2');
    If (IsObj($Obj_WMIService)) And (Not @error) Then
        Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_DiskDrive Where MediaLoaded=1') ; for ready devices
        Local $Obj_Items
        For $Obj_Items In $Col_Items
            $Drives[Number($Drives[0][0] + 2)][5] = $Obj_Items.caption
            $strdeviceid = StringReplace($Obj_Items.deviceid, "\", "\\")
            $colpartitions = $Obj_WMIService.execquery('ASSOCIATORS OF {Win32_DiskDrive.DeviceID="' & $strdeviceid & '"}' & "WHERE AssocClass = Win32_DiskDriveToDiskPartition")
            For $var1 In $colpartitions
                $collogicaldisks = $Obj_WMIService.execquery('ASSOCIATORS OF {Win32_DiskPartition.DeviceID="' & $var1.deviceid & '"}' & "WHERE  AssocClass = Win32_LogicalDiskToPartition")
                For $var2 In $collogicaldisks
                    $Drives[0][0] += 1
                    $Drives[Number($Drives[0][0] + 1)][0] = $var2.deviceid
                    $Drives[Number($Drives[0][0] + 1)][1] = $Obj_Items.model
                    $Drives[Number($Drives[0][0] + 1)][2] = $var1.primarypartition
                    $Drives[Number($Drives[0][0] + 1)][3] = $var2.filesystem
                    $Drives[Number($Drives[0][0] + 1)][4] = $Obj_Items.pnpdeviceid
                    $Drives[Number($Drives[0][0] + 1)][5] = $Obj_Items.caption
                Next
            Next
        Next
        $Drives[0][0] += 1
        Return $Drives
    Else
        Return 0
    EndIf
EndFunc   ;==>_Drives_Determine

Example:

#include <Array.au3>
#include "DriveInfo.au3"
Opt('MustDeclareVars', 1) ; 0 = No, 1 = Require pre-declare.
Global $Drives_Array = _Drives_Determine()
;~ If ($Drives_Array <> 0) Then _ArrayDisplay($Drives_Array, 'Drives', Default, Default, Default, "Drive|Moedl|Is Primary?|File System|PNP Device ID|Caption")
If ($Drives_Array <> 0) Then _ArrayDisplay($Drives_Array, 'DriveInfo', $Drives_Array[0][0], Default, Default, "Drive|Moedl|Is Primary?|File System|PNP Device ID|Caption")
Edited by Muzaiyan
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...