Jump to content

Problem with _GUICtrlListView_AddSubItem


Osixs
 Share

Recommended Posts

Hello all >_<

My script consists to take all the ips of the local or remote machine and to display in a _GUICtrlListView_AddSubItem.

But when I have more ips on the pc or I see it as the latest find.

How to display IP1, IP2, IP3 in _GUICtrlListView_AddSubItem. ?

that's my code:

$colItemsNetwork = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL")    
        $y = _GUICtrlListView_GetItemCount($ListView1)

    ; Add Ip Address info
    For $objItem In $colItemsNetwork
        If ($objItem.IPAddress) <> "0.0.0.0" Then
            For $o = 0 To UBound($objItem.IPAddress)
                $getipadd = $objItem.IPAddress(0)
            Next
        EndIf   
        _GUICtrlListView_AddSubItem($ListView1, $y, $getipadd, 2, 3)
    Next
    ; End Ip Adress info

Thank you in advance.

Good day.

Link to comment
Share on other sites

$objWMIService = ObjGet('winmgmts:\\.\root\CIMV2')
$colItemsNetwork = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE", "WQL")    


; Add Ip Address info
For $objItem In $colItemsNetwork
    If IsArray($objItem.IPAddress) And ($objItem.IPAddress(0) <> "0.0.0.0") Then _
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1), $objItem.IPAddress(0), 2, 3)
Next
; End Ip Adress info

Link to comment
Share on other sites

What do you want it to do? You want the IP addresses to fit each in a new row or each in an increased column?

$objWMIService = ObjGet('winmgmts:\\.\root\CIMV2')
$colItemsNetwork = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE", "WQL")    


; Add Ip Address info
For $objItem In $colItemsNetwork
    Local $iRow = _GUICtrlListView_AddItem($hListView1, 'Text')
    Local $iColumn = 1
    
    If IsArray($objItem.IPAddress) Then
        For $i = 0 To UBound($objItem.IPAddress)-1
            If $objItem.IPAddress($i) <> "0.0.0.0" Then
                _GUICtrlListView_AddSubItem($hListView1, $iRow, $objItem.IPAddress($i), $iColumn)
                $iColumn += 1
            EndIf
        Next
    EndIf
Next
Edited by Authenticity
Link to comment
Share on other sites

Hello all >_<

i have test with: _ArrayToString but i have allways the same ip address in my row

; Add Ip Address info
    For $objItem In $colItemsNetwork
        If ($objItem.IPAddress) <> "0.0.0.0" Then
            For $o = 0 To UBound($objItem.IPAddress)
                $getipa[$o] = $objItem.IPAddress(0)
                _GUICtrlListView_AddSubItem($ListView1, $y, _ArrayToString($getipa, " ", 0, 7), 2, 3)
            Next
        EndIf   
    Next
    ; End Ip Adress info

Thank you in advance.

Good day.

Link to comment
Share on other sites

Thank you for your reply.

Yes I looked at your code, which is very good but I Columns created for every ip address.

Me I would like to have all my ip addresses in the same row ( case ) is that possible?

Thank you in advance.

Link to comment
Share on other sites

$objWMIService = ObjGet('winmgmts:\\.\root\CIMV2')
$colItemsNetwork = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE", "WQL")    


; Add Ip Address info
For $objItem In $colItemsNetwork
    Local $iRow = _GUICtrlListView_GetItemCount($hListView1)-1
    Local $sText = ''
    
    If IsArray($objItem.IPAddress) Then
        For $i = 0 To UBound($objItem.IPAddress)-1
            If $objItem.IPAddress($i) <> "0.0.0.0" Then
                $sText &= $objItem.IPAddress($i) & ' '
            EndIf
        Next
        
        _GUICtrlListView_AddSubItem($hListView1, $iRow, $sText, 2, 3)
    EndIf
Next

Link to comment
Share on other sites

Hello,

Thank you very much for your help Authenticity.

But I still have a ip address in my case (row)

I put a print screen to show you:

Posted Image

In the network adapters tab you can see that I have several network interfaces and therefore multiple IP that I would like to put in my box ( row ) ip address.

Thank you in advance.

Good day to you all.

And thank you for your help.

Link to comment
Share on other sites

Hi, if you can see them in the loop it means that each belong to another item in the collection returned from the ExecQuery method. In this can, I guess this would be correct. Though, a little bit of testing would get you there >_<.

$objWMIService = ObjGet('winmgmts:\\.\root\CIMV2')
$colItemsNetwork = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE", "WQL")    

Local $iRow = _GUICtrlListView_GetItemCount($hListView1)-1
Local $sText = ''

; Add Ip Address info
For $objItem In $colItemsNetwork
    If IsArray($objItem.IPAddress) Then
        For $i = 0 To UBound($objItem.IPAddress)-1
            If $objItem.IPAddress($i) <> "0.0.0.0" Then
                $sText &= $objItem.IPAddress($i) & ' '
            EndIf
        Next
    EndIf
Next

_GUICtrlListView_AddSubItem($hListView1, $iRow, $sText, 2, 3)

..if no, forgive my innocent assumption.

Link to comment
Share on other sites

Authenticity thank you very much for your help and your very efficasse speed and quality of response:)

I just modify the code for the IPV4

Local $iRow = _GUICtrlListView_GetItemCount($ListView1)-1
    Local $sText = ''

    ; Add Ip Address info
    For $objItem In $colItemsNetwork
        If IsArray($objItem.IPAddress) Then
            For $i = 0 To UBound($objItem.IPAddress(0))
                If $objItem.IPAddress(0) <> "0.0.0.0" Then
                    $sText &= $objItem.IPAddress(0) & ' '
                EndIf
            Next
        EndIf
    Next

    _GUICtrlListView_AddSubItem($ListView1, $iRow, $sText, 2, 3)

I thank you and wish you a good day.

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