Jump to content

Array Help


Recommended Posts

i have this script whcih queries list of software installed using the WMI function. my output is only message boxes. i want to output the list into array. how will i do that?

below is the code:

#include <Array.au3>

$strComputer = Inputbox("Software", "Enter computer name.")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$colSoftware = $objWMIService.ExecQuery ("Select * from Win32_Product")

For $objWMIService in $colSoftware

MsgBox(64, "Software List", "Softwares Names: " & $objWMIService.Name)

Next

Link to comment
Share on other sites

JohnRichard

Example:

#include <Array.au3> ;only for array display

Global $aSoft[1]

$strComputer = Inputbox("Software", "Enter computer name.")
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colSoftware = $objWMIService.ExecQuery ("Select * from Win32_Product")

For $objWMIService in $colSoftware
    $aSoft[0] += 1
    ReDim $aSoft[$aSoft[0] + 1]
    $aSoft[$aSoft[0]] = $objWMIService.Name
Next

_ArrayDisplay($aSoft)
Link to comment
Share on other sites

i have this script whcih queries list of software installed using the WMI function. my output is only message boxes. i want to output the list into array. how will i do that?

below is the code:

#include <Array.au3>

$strComputer = Inputbox("Software", "Enter computer name.")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$colSoftware = $objWMIService.ExecQuery ("Select * from Win32_Product")

For $objWMIService in $colSoftware

MsgBox(64, "Software List", "Softwares Names: " & $objWMIService.Name)

Next

And here is another way to do the same thing

#include <Array.au3>
Local $res

$strComputer = InputBox("Software", "Enter computer name.")
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colSoftware = $objWMIService.ExecQuery("Select * from Win32_Product")

For $objWMIService In $colSoftware
    $res &= $objWMIService.Name & @LF
Next

MsgBox(64, "Software List", $res)

$aList = StringSplit(StringTrimRight($res, 1), @LF);StringTrimRight removes last @LF
_ArrayDisplay($aList, "Software List")
Link to comment
Share on other sites

works great rasim. thanks. what does this operator means +=? What is the function of the REDIM. i have never used Redim. maybe i should know a lot more with it since i'm starting to learn working with array. One more question, how will i give a name of the column in the array. Like Row should be any name and column 1 should be any name and so forth.

thanks again. i really appreciate your help looking with my problem.

Link to comment
Share on other sites

ReDim allows you to change an arrays dimensions without changing the current data.

"+=" means to add the value to the original and store as the original variable: so '$var += 1' would add 1 to the value of $var and save the new value as $var.

For your third question: 'how will i give a name of the column in the array. Like Row should be any name and column 1 should be any name and so forth.', I have no idea what you are asking here. Can you try re phrasing the question?

Link to comment
Share on other sites

this is the code for the ARRAY

_ArrayDisplay($aList, "Software List")

when the array result was displayed it has a default column name below

Row | Column 0

_________________

[0] | Adobe

[1] | Winzip

my question is, how will i change the column name like

Number | Installed Software

_______________________

[0] | Adobe

[1] | WinZip

Link to comment
Share on other sites

this is the code for the ARRAY

_ArrayDisplay($aList, "Software List")

when the array result was displayed it has a default column name below

Row | Column 0

_________________

[0] | Adobe

[1] | Winzip

my question is, how will i change the column name like

Number | Installed Software

_______________________

[0] | Adobe

[1] | WinZip

Edit a _ArrayDisplay() function in the c:\Program Files\AutoIt3\Include\Array.au3 file.
Link to comment
Share on other sites

why is that the array is not working on this code? i am querying computer network's information.

i have the WMI values of NIC namely:

objitem.DHCPServer & @CRLF

objitem.DNSHostName & @CRLF _

objitem.MACAddress & @CRLF _

objitem.DefaultIPGateway & @CRLF

objitem.IPAddress & @CRLF

objitem.IPSubnet & @CRLF

objItem.Description

here is the script.

#include <Array.au3>

Local $res

$strComputer = InputBox("Software", "Enter computer name.")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For $objWMIService In $colNicConfigs

$res &= $objWMIService.DHCPServer & @CRLF _

& $objWMIService.DNSHostName & @CRLF _

& $objWMIService.MACAddress & @CRLF _

& $objWMIService.DefaultIPGateway & @CRLF _

& $objWMIService.IPAddress & @CRLF _

& $objWMIService.IPSubnet & @CRLF

& $objWMIService.Description

Next

MsgBox(64, "Software List", $res)

$aList = StringSplit(StringTrimRight($res, 1), @LF)

_ArrayDisplay($aList, "Software List")

Link to comment
Share on other sites

Found a few potential problems:

#include <Array.au3>
Local $res

$strComputer = InputBox("Software", "Enter computer name.")
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For $objWMIService In $colNicConfigs
$res &= $objWMIService.DHCPServer & @LF & _
$objWMIService.DNSHostName & @LF & _
$objWMIService.MACAddress & @LF & _
$objWMIService.DefaultIPGateway & @LF & _
$objWMIService.IPAddress & @LF & _
$objWMIService.IPSubnet & @LF & _
$objWMIService.Description & @LF 
Next

MsgBox(64, "Software List", $res)

$aList = StringSplit(StringTrimRight($res, 1), @LF)
_ArrayDisplay($aList, "Software List")

1 what you were doing with the For look and joing the values was incorrect. I fixed them out. Using @CRLF as your deliminator was incorrect also, as you only split by @LF. Thats pretty much all I changed. The OBJGet failed for me, but I am not sure about it.

Link to comment
Share on other sites

i noticed as well the error joining the values. i manage do make it work using this script. but my problem is, i need to change the column name to something identifiable rather than the default array columns (Rows, Col 0, Col 1, Col 2,...and so on)

how will i do it?

code:

#include <Array.au3> ;only for array display

Local $objItem

Dim $NICInfo[1][5], $i = 1

$strComputer = Inputbox("Software", "Enter computer name.")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

If IsObj($colNicConfigs) Then

For $objItem in $colNicConfigs

ReDim $NICInfo[uBound($NICInfo) + 1][4]

$NICInfo[$i][0] = $objItem.DHCPServer & @CRLF

$NICInfo[$i][1] = $objItem.DNSHostName & @CRLF

$NICInfo[$i][2] = $objItem.MACAddress & @CRLF

$NICInfo[$i][3] = $objItem.Description & @CRLF

$i += 1

Next

$NICInfo[0][0] = UBound($NICInfo) - 1

If $NICInfo[0][0] < 1 Then

SetError(1, 1, 0)

EndIf

Else

SetError(1, 2, 0)

EndIf

_ArrayDisplay($NICInfo, "Network Info")

Link to comment
Share on other sites

As mention by Rasim previously-

Edit a _ArrayDisplay() function in the c:\Program Files\AutoIt3\Include\Array.au3 file.

I would just create your own GUI and have it how you want it ;)

Link to comment
Share on other sites

i'm not a so called programmer to edit the array function. wha't i've seen there to edit is the default name of the array.

maybe i am referring to a ListView item wherein i can create my column with distinguished name.

anyway thanks i'm so excited to see how you edit the code the way i want it. i have tried to create a Listview item on my code but i can't seem to display the array values on the listview. can you please check this also...i appreaciate all of your help.

code:

#include <Array.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Local $objItem, $listview, $Data

Dim $NICInfo[1][4], $i = 1

GUICreate("Network Information", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)

$listview = GUICtrlCreateListView("DHCP Server|DNSHostName|MACAddress|Description", 10, 10, 200, 150)

GUICtrlSetState(-1, $GUI_DROPACCEPTED)

GUISetState()

$strComputer = Inputbox("Software", "Enter computer name.")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

If IsObj($colNicConfigs) Then

For $objItem in $colNicConfigs

ReDim $NICInfo[uBound($NICInfo) + 1][4]

$NICInfo[$i][0] = $objItem.DHCPServer

$NICInfo[$i][1] = $objItem.DNSHostName

$NICInfo[$i][2] = $objItem.MACAddress

$NICInfo[$i][3] = $objItem.Description

;$NICInfo[$i][3] = $objItem.IPAddress

$i += 1

Next

$NICInfo[0][0] = UBound($NICInfo) - 1

If $NICInfo[0][0] < 1 Then

SetError(1, 1, 0)

EndIf

Else

SetError(1, 2, 0)

EndIf

$array = _ArrayDisplay($NICInfo, "Network Information List")

$Data = GUICtrlCreateListViewItem($array, $listview)

GUICtrlSetData($Data, $listview)

Link to comment
Share on other sites

Lets remove all the OBJ stuff and get a basic GUI working now. What do you think of this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

Local $objItem, $listview, $Data
Dim $NICInfo[6][4], $i = 1

GUICreate("Network Information", 520, 350, 100, 200, -1, $WS_EX_ACCEPTFILES)
$listview = GUICtrlCreateListView("", 10, 10, 495, 330)
_GUICtrlListView_AddColumn ($listview, "DHCP Server", 100)
_GUICtrlListView_AddColumn ($listview, "DNSHostName", 100)
_GUICtrlListView_AddColumn ($listview, "MACAddress", 100)
_GUICtrlListView_AddColumn ($listview, "Description", 180)

GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState()

For $i = 1 To 5
    $NICInfo[$i][0] = "DHCP"
    $NICInfo[$i][1] = "DNS" 
    $NICInfo[$i][2] = "MAC" 
    $NICInfo[$i][3] = "DESCRIPTION" 
;$NICInfo[$i][3] = $objItem.IPAddress
Next
$NICInfo[0][0] = UBound($NICInfo) - 1

;$Data = GUICtrlCreateListViewItem($array, $listview)
;GUICtrlSetData($Data, $listview)

For $i = 1 To $NICInfo[0][0]
    $idx = _GUICtrlListView_AddItem ($listview, $NICInfo[$i][0])
    _GUICtrlListView_AddSubItem ($listview, $idx, $NICInfo[$i][1], 1)
    _GUICtrlListView_AddSubItem ($listview, $idx, $NICInfo[$i][2], 2)
    _GUICtrlListView_AddSubItem ($listview, $idx, $NICInfo[$i][3], 3)
Next

While 1
    $nMsg = GUIGetMsg ()
    Switch $nMsg
        Case -3
            Exit
    EndSwitch
WEnd

Now see if u can add in the Obj stuff, and see how you go. ;)

Link to comment
Share on other sites

  • 2 weeks later...

hi brettf. i manage to add the Obj stuff on the script and it works as i want it to be. but i have another question. i wanted to copy the details listed in the listview item. say when item is selected and make a right click on it, i can have option to copy and paste it somewhere like in notepad. here is what i have right now.

i appreciate any help. thanks

code:

#include <Array.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Local $objItem, $listview, $Data

Dim $NICInfo[1][4], $i = 1

GUICreate("Network Information", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)

$listview = GUICtrlCreateListView("DHCP Server|DNSHostName|MACAddress|Description", 10, 10, 200, 150)

GUICtrlSetState(-1, $GUI_DROPACCEPTED)

GUISetState()

$strComputer = Inputbox("Network Information", "Enter computer name.")

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

If IsObj($colNicConfigs) Then

For $objItem in $colNicConfigs

ReDim $NICInfo[uBound($NICInfo) + 1][4]

$NICInfo[$i][0] = $objItem.DHCPServer

$NICInfo[$i][1] = $objItem.DNSHostName

$NICInfo[$i][2] = $objItem.MACAddress

$NICInfo[$i][3] = $objItem.Description

;$NICInfo[$i][3] = $objItem.IPAddress

$i += 1

Next

$NICInfo[0][0] = UBound($NICInfo) - 1

If $NICInfo[0][0] < 1 Then

SetError(1, 1, 0)

EndIf

Else

SetError(1, 2, 0)

EndIf

$array = _ArrayDisplay($NICInfo, "Network Information List")

$Data = GUICtrlCreateListViewItem($array, $listview)

GUICtrlSetData($Data, $listview)

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