Jump to content
Sign in to follow this  

Trying to understand Array's

Recommended Posts


I am trying to compare a current model of PC (Which I get from doing a WMI call) to a list of models listed in a file on a network share.

The process I do is as follows:


This script is designed to automatically deploy the HP driver set based on Model


#include "Win32_ComputerSystem.AU3"
#include <Array.au3>
#include <file.au3>

Dim $Locfilename = "C:\Model.txt"
Dim $Netfilename = "\\<Servername>\drivers\Model.txt"

Dim $Mapdrive, , $avArray

If Not _FileReadToArray($Netfilename,$avArray) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
For $x = 1 to $avArray[0]
    Msgbox(0,'Record:' & $x, $avArray[$x])

The WMI code is as follows:

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Filename = "C:\Model.txt"

$Output = $Output & "Computer: " & $strComputer  & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & $objItem.Model & @CRLF
      FileWrite($Filename, $objItem.Model & @CRLF)
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystem" )

Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))

Basically, I write the output of the WMI call to a file called c:\Model.txt, then open a file located on network share which is already pre-populated with a list of ALL current machines we have, and want to search and compare for the model number that was generated from the WMI call against the list of models. Based on this result I will do another piece of code which is not required for this complex question!?!!?!

I have managed to read the network file into an array, but not sure how I search the array for the result that was produced in the C:\Model.txt.

How do I do this?

Hope this makes sense??


Share this post

Link to post
Share on other sites

$TheOneThatIWant = 0
For $x = 1 to $avArray[0]
    Msgbox(0,'Record:' & $x, $avArray[$x])
    If $avArray[$x]='the one that you want' then $TheOneThatIWant = $x
If $TheOneThatIWant Then MsgBox(0,'Found','The one you want is in element #' & $TheOneThatIWant)

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