Sign in to follow this  
Followers 0
lyledg

Trying to understand Array's

2 posts in this topic

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:

#cs

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

#ce

#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)
   Exit
EndIf
For $x = 1 to $avArray[0]
    Msgbox(0,'Record:' & $x, $avArray[$x])
Next

The WMI code is as follows:

; Generated by AutoIt Scriptomatic

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

$Output=""
$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)
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystem" )
Endif


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))
EndFunc

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

Cheers

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
Next
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  
Followers 0