Deye Posted January 23, 2020 Share Posted January 23, 2020 (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 January 23, 2020 by Deye Link to comment Share on other sites More sharing options...
Nine Posted January 23, 2020 Share Posted January 23, 2020 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 Deye 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Deye Posted January 23, 2020 Author Share Posted January 23, 2020 Thanks Nine Must be a way to make it work on removables $objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2") $colDevice = $objWMIService.ExecQuery("SELECT * from Win32_DiskDrive") For $objItem In $colDevice ConsoleWrite($objItem.caption & @LF) Next Link to comment Share on other sites More sharing options...
Deye Posted January 24, 2020 Author Share Posted January 24, 2020 using DriveGetDrive("all") Gets removables as well Link to comment Share on other sites More sharing options...
Subz Posted January 24, 2020 Share Posted January 24, 2020 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 Deye 1 Link to comment Share on other sites More sharing options...
Deye Posted January 24, 2020 Author Share Posted January 24, 2020 (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 January 24, 2020 by Deye Link to comment Share on other sites More sharing options...
Nine Posted January 24, 2020 Share Posted January 24, 2020 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Deye Posted January 24, 2020 Author Share Posted January 24, 2020 (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 January 24, 2020 by Deye Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now