LyndaSing7 Posted December 12, 2013 Share Posted December 12, 2013 (edited) For example, I would like to copy the only column 3 from the hardwareID column, may I know what method that is suitable to be use? below is my code, #include <Array.au3> $USB = USBDevices() If IsArray($USB) Then _ArrayDisplay($USB) Func USBDevices() Local $USB $ComputerName = "." $wmiServices = ObjGet("winmgmts:{impersonationLevel=Impersonate}!//" & $ComputerName) $wmiDiskDrives = $wmiServices.ExecQuery("SELECT Model, InterfaceType, PNPDeviceID, Caption, DeviceID, SerialNumber FROM Win32_DiskDrive") Local $USB[1][5] For $wmiDiskDrive In $wmiDiskDrives $wmiDiskPartitions = $wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition") For $wmiDiskPartition In $wmiDiskPartitions $wmiLogicalDisks = $wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition") For $wmiLogicalDisk In $wmiLogicalDisks If $wmiDiskDrive.InterfaceType = 'USB' Then $USB[0][0] += 1 ReDim $USB[$USB[0][0]+1][5] $USB[$USB[0][0]][0] = $wmiLogicalDisk.DeviceID $USB[$USB[0][0]][1] = $wmiDiskDrive.Model $USB[$USB[0][0]][2] = $wmiDiskDrive.InterfaceType $USB[$USB[0][0]][3] = $wmiDiskDrive.PNPDeviceID $USB[$USB[0][0]][4] = $wmiDiskDrive.SerialNumber EndIf Next Next Next Return $USB EndFunc thank you and appreciate if any able to help ^^ Edited December 13, 2013 by LyndaSing7 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 12, 2013 Moderators Share Posted December 12, 2013 LyndaSing7,Use _GUICtrlListView_GetItemText and set the $iSubItem parameter. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mikell Posted December 12, 2013 Share Posted December 12, 2013 Or ControlListView($my_gui, "", $listview, "GetText", 1, 4) Link to comment Share on other sites More sharing options...
LyndaSing7 Posted December 13, 2013 Author Share Posted December 13, 2013 (edited) Thank you M23 and mikell respond, I'm till newbie to AutoIT so I not so clear with clue given by you guys. It's any example that able to make me understand? Thank you. Edited December 13, 2013 by LyndaSing7 Link to comment Share on other sites More sharing options...
kylomas Posted December 13, 2013 Share Posted December 13, 2013 LyndaSing7, This will display the contents of column 3 in the console area if you run the script from the SCiTE editor (F5). expandcollapse popup#include <Array.au3> $USB = USBDevices() If IsArray($USB) Then _ArrayDisplay($USB) ConsoleWrite('And this is the contents of column 3:' & @LF) for $1 = 0 to ubound($USB) - 1 ConsoleWrite($USB[$1][3] & @LF) next endif Func USBDevices() Local $USB $ComputerName = "." $wmiServices = ObjGet("winmgmts:{impersonationLevel=Impersonate}!//" & $ComputerName) $wmiDiskDrives = $wmiServices.ExecQuery("SELECT Model, InterfaceType, PNPDeviceID, Caption, DeviceID, SerialNumber FROM Win32_DiskDrive") Local $USB[1][5] For $wmiDiskDrive In $wmiDiskDrives $wmiDiskPartitions = $wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition") For $wmiDiskPartition In $wmiDiskPartitions $wmiLogicalDisks = $wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition") For $wmiLogicalDisk In $wmiLogicalDisks If $wmiDiskDrive.InterfaceType = 'USB' Then $USB[0][0] += 1 ReDim $USB[$USB[0][0]+1][5] $USB[$USB[0][0]][0] = $wmiLogicalDisk.DeviceID $USB[$USB[0][0]][1] = $wmiDiskDrive.Model $USB[$USB[0][0]][2] = $wmiDiskDrive.InterfaceType $USB[$USB[0][0]][3] = $wmiDiskDrive.PNPDeviceID $USB[$USB[0][0]][4] = $wmiDiskDrive.SerialNumber EndIf Next Next Next Return $USB EndFunc Do you know that you are only showing USB devices that are READY? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
LyndaSing7 Posted December 13, 2013 Author Share Posted December 13, 2013 yes, I do know the code able to display the USB ,kylomas. but I just want to copy the USB ID part of the text but do not want to copy the USB name and the others column ,just want the copy and select the col 3 . (sorry for my bad english) Link to comment Share on other sites More sharing options...
kylomas Posted December 13, 2013 Share Posted December 13, 2013 LyndaSing7, yes, I do know the code able to display the USB ,kylomas. Only those that are READY (have a device plugged in). just want the copy and select the col 3 . You can access column 3 directly, as I've shown. Perhaps I don't understand what you are trying to do. The array is created by the script that you posted. Do you want to put column 3 in a file, on the clip board, in a spreadsheet, etc...?? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
LyndaSing7 Posted December 13, 2013 Author Share Posted December 13, 2013 (edited) When I was selected the text in the column, it was highlighted the the full line of column and when click copy button, all of the column text selected was copy all. but what I want is only copy the column 3, column 3 only is selected and copy the text in the column into notepad. not full information is selected example : [1]|F:|Kingston DT 101 G2 USB Device|USB|USBSTORDISK&VEN_KINGSTON&PROD_DT_101_G2&REV_PMAP0019E06B07F7BA70677C015A&0| but I only wan the output that is copy is USBSTORDISK&VEN_KINGSTON&PROD_DT_101_G2&REV_PMAP0019E06B07F7BA70677C015A&0 Edited December 13, 2013 by LyndaSing7 Link to comment Share on other sites More sharing options...
mikell Posted December 13, 2013 Share Posted December 13, 2013 lyndasing7, You can't do this using _ArrayDisplay, as it is a func used for debug only The 2 possible solutions are : either build your own listview to display the array and then use Melba's code or mine, or bypass the listview and grab the info directly from the array as kylomas suggested Link to comment Share on other sites More sharing options...
kylomas Posted December 13, 2013 Share Posted December 13, 2013 LyndaSing7, This writes the 3RD column to a file names USB.TXT in whatever dir you run the script from... expandcollapse popup#include <Array.au3> $USB = USBDevices() If IsArray($USB) Then for $1 = 0 to ubound($USB) - 1 filewrite(@scriptdir & '\USB.TXT',$USB[$1][3] & @LF) next endif shellexecute(@scriptdir & '\USB.TXT') Func USBDevices() Local $USB $ComputerName = "." $wmiServices = ObjGet("winmgmts:{impersonationLevel=Impersonate}!//" & $ComputerName) $wmiDiskDrives = $wmiServices.ExecQuery("SELECT Model, InterfaceType, PNPDeviceID, Caption, DeviceID, SerialNumber FROM Win32_DiskDrive") Local $USB[1][5] For $wmiDiskDrive In $wmiDiskDrives $wmiDiskPartitions = $wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition") For $wmiDiskPartition In $wmiDiskPartitions $wmiLogicalDisks = $wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition") For $wmiLogicalDisk In $wmiLogicalDisks If $wmiDiskDrive.InterfaceType = 'USB' Then $USB[0][0] += 1 ReDim $USB[$USB[0][0]+1][5] $USB[$USB[0][0]][0] = $wmiLogicalDisk.DeviceID $USB[$USB[0][0]][1] = $wmiDiskDrive.Model $USB[$USB[0][0]][2] = $wmiDiskDrive.InterfaceType $USB[$USB[0][0]][3] = $wmiDiskDrive.PNPDeviceID $USB[$USB[0][0]][4] = $wmiDiskDrive.SerialNumber EndIf Next Next Next Return $USB EndFunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
LyndaSing7 Posted December 16, 2013 Author Share Posted December 16, 2013 Thank you so much, kylomas and mikell I had solved it by using yours methods. 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