Sign in to follow this  
Followers 0
LyndaSing7

How to copy the text from the selected colum

11 posts in this topic

#1 ·  Posted (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 ^^

post-82006-0-40695700-1386906037_thumb.p

Edited by LyndaSing7

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by LyndaSing7

Share this post


Link to post
Share on other sites

LyndaSing7,

This will display the contents of column 3 in the console area if you run the script from the SCiTE editor (F5).

#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

Share this post


Link to post
Share on other sites

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)
 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#8 ·  Posted (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

 

post-82006-0-89470300-1386917481_thumb.p

Edited by LyndaSing7

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

LyndaSing7,

This writes the 3RD column to a file names USB.TXT in whatever dir you run the script from...

#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

Share this post


Link to post
Share on other sites

Thank you so much, kylomas and mikell I had solved it by using yours methods. 

Share this post


Link to post
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
Sign in to follow this  
Followers 0