Jump to content

How to copy the text from the selected colum


Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

LyndaSing7,

Use _GUICtrlListView_GetItemText and set the $iSubItem parameter. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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

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...