Jump to content

Recommended Posts

Posted (edited)

Hi

@ trying to get the "Manufacturer name" by a disk Letter

@ finding a way to combine the both from passing just the disk letter:

Not sure how it should get done:

Local $a = DriveGetDrive("all")
For $i = 1 To $a[0]
    _DiskManufacturer(StringUpper($a[$i]))
Next

Func _DiskManufacturer($disk) ;Manufacturer
    $objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2")
    $colDevice = $objWMIService.ExecQuery("SELECT * from Win32_LogicalDisk where DeviceID = '" & $disk & "'")
    For $objItem In $colDevice
        If $objItem.Caption = $disk Then
            $colDevice2 = $objWMIService.ExecQuery("SELECT * from Win32_DiskDrive")
            For $objItem In $colDevice2
                ConsoleWrite($objItem.caption & @LF)
                ExitLoop
            Next
        EndIf
    Next
EndFunc   ;==>_DiskManufacturer

Thanks

Deye

Edited by Deye
Posted

This works for hard drives (not removable) :

#include <Constants.au3>

Local $aDisk = DriveGetDrive($DT_FIXED)
For $i = 1 To $aDisk[0]
  ConsoleWrite (_DiskManufacturer(StringUpper($aDisk[$i])) & @CRLF)
Next

Func _DiskManufacturer($sDisk)
  Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
  Local $col = $objWMIService.ExecQuery("SELECT * from Win32_LogicalDiskToPartition")
  Local $sDiskNumber = "", $sDiskPhys = ""
  For $objItem In $col
    If StringRegExp($objItem.Dependent, 'DeviceID="(.+?)"', $STR_REGEXPARRAYMATCH)[0] = $sDisk Then
      $sDiskNumber = StringRegExp($objItem.Antecedent, 'DeviceID="(.+?),', $STR_REGEXPARRAYMATCH)[0]
      ExitLoop
    EndIf
  Next
  If $sDiskNumber = "" Then Return SetError(1, 0, "")
  ConsoleWrite($sDiskNumber & @CRLF)
  $col = $objWMIService.ExecQuery("SELECT * from Win32_DiskDriveToDiskPartition")
  For $objItem In $col
    If StringRegExp($objItem.Dependent, 'DeviceID="(.+?),', $STR_REGEXPARRAYMATCH)[0] = $sDiskNumber Then
      $sDiskPhys = StringReplace(StringRegExp($objItem.Antecedent, 'DeviceID="(.+?)"', $STR_REGEXPARRAYMATCH)[0], "\\", "\")
      ExitLoop
    EndIf
  Next
  If $sDiskPhys = "" Then Return SetError(2, 0, "")
  ConsoleWrite($sDiskPhys & @CRLF)
  $col = $objWMIService.ExecQuery("SELECT * from Win32_DiskDrive")
  For $objItem In $col
    If $objItem.DeviceId = $sDiskPhys Then
      Return $objItem.caption
    EndIf
  Next
  Return SetError(3, 0, "")
EndFunc   ;==>_DiskManufacturer

 

Posted

Thanks Nine 

Must be a way to make it work on removables :huh2:

$objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2")
$colDevice = $objWMIService.ExecQuery("SELECT * from Win32_DiskDrive")
For $objItem In $colDevice
    ConsoleWrite($objItem.caption & @LF)
Next

 

Posted

Another way

$ComputerName = "."
$wmiServices  = ObjGet("winmgmts:{impersonationLevel=Impersonate}!//" & $ComputerName)
$wmiDiskDrives =  $wmiServices.ExecQuery("SELECT Caption, DeviceID FROM Win32_DiskDrive")

For $wmiDiskDrive In $wmiDiskDrives
    $query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
    $wmiDiskPartitions = $wmiServices.ExecQuery($query)

    For $wmiDiskPartition In $wmiDiskPartitions
        $wmiLogicalDisks = $wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
        For $wmiLogicalDisk In $wmiLogicalDisks
            ConsoleWrite("DiskDrive Caption = " & $wmiDiskDrive.Caption & @CRLF & _
            "DiskDrive DeviceID = " & $wmiDiskDrive.DeviceID & @CRLF & _
            "DiskPartition = " & $wmiDiskPartition.DeviceID & @CRLF & _
            "LogicalDisk DeviceID = "& $wmiLogicalDisk.DeviceID & @CRLF & @CRLF)
        Next
    Next
Next

 

Posted (edited)

when i have set up detection to new arrivals or departures of drives in the script

where I rebuild the list I keep getting @error -2147417843 from the $objWMIService = ObjGet part

tried setting $objWMIService to static or global but nothing seems to work 

beats me where this error is creeping from (must be of type "Object")

a reproducer wont do because it always seems to work

any ideas ?

Thanks

Edited by Deye
Posted

You shouldn't recreate the object all the time.  Once it is created, you can reuse the object for as long as the script doesn't exit.  On the other hand, recreating it should not create such a problem.  You could try to run it x64, see if that solves the issue.

Posted (edited)

tried a lot of stuff to try and fix this to no avail

the isobject will complain if not declared ..etc maybe its the error checking in site that is confusing me 

should I  find away to disable it and try again ?

Edit: nope, it errors with autoit ..

Too bad there is no "Object" that will act like "Local" or  "Global" 

its that they don't mix so well with Autoit's handling logic hence the errors ..

 

Edited by Deye

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...