Jump to content

Trying to compare two arrays and return value


Recommended Posts

  • Moderators

I am working on a script to confirm that application installs on old and new equipment match. To provide a bit of background, all application installs are automated through Altiris. The applications are placed in "C:\Program Files\Altiris\Altiris Agent\Software Delivery\" under a folder that corresponds to a GUID for that application. The point I am trying to get to is to have a couple of arrays, one that has the friendly name and one that has the GUID. The script does a straight comparison of the directory on both machines, and if it finds any discrepancies it notifies the technician ("Microsoft Viso is not installed on ...", etc.). I've had some limited success with the code below, writing the existing folders on both machines into arrays. I can display them individually, but what I get back is the GUID.

#include <Array.au3>

$pc = InputBox("Compare Altiris Installs", "Please enter the asset tag of the machine to connect to.")
$dir1 = @ProgramFilesDir & "\Altiris\Altiris Agent\Software Delivery\"
$dir2 = '"[url="file://"]\\'[/url] & $pc & '\C$\Program Files\Altiris\Altiris Agent\Software Delivery\"'

Dim $myArray1[1]
Dim $myArray2[1]

Local $appID[130]
$appID[0] = "Office 2007"
$appID[1] = "Visio Pro"
$appID[2] = "Adobe Reader"
$appID[3] = "Adobe Flash Player"
(Text omitted...)

Local $appGUID[130]
$appGUID[0] = "{36bb7203-c642-4e06-92cb-1dc82bf21357}"
$appGUID[1] = "{2c33b47f-9efd-4d5a-a7a0-74ec7b4c321d}"
$appGUID[2] = "{ef1364d6-76be-4fad-9790-faa534baa9ba}"
$appGUID[3] = "{daab71ce-066d-4fb9-b83a-8d6458b7110b}"
(Text omitted...)

For $element in $appGUID
  If FileExists($dir1 & $element) Then
   _ArrayAdd($myArray1, $element)
   $rows = UBound($myArray1)
   ReDim $myArray1[$rows]
  EndIf
Next

For $element in $appGUID  
  If FileExists($dir2 & $element) Then
   _ArrayAdd($myArray2, $element)
   $rows = UBound($myArray2)
   ReDim $myArray2[$rows]
  EndIf
Next

_ArraySort($myArray1)
_ArraySort($myArray2)

What I would like to do is get to the point where I can compare the new PC, $myArray2, with the current, $myArray1, and take not of any differences. Not having much success with that, I've tried a straight comparison with FileExists, and can get it to write to a text file using a $string1 = $string2 comparison. What I cannot figure out is how to convert the GUID to the friendly name. The GUID and the common name should have the same Index in their respective arrays, so I would think there would be a way to convert the two, but I'm stumped as to how to accomplish it. Any suggestions or constructive criticism would be greatly appreciated.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Just build more arrays and bounce them off each other, i would probably steer clear of sorting if you plan on them remaining as you built them.

btw: Changed your fileexists to nots for testing, easier.

: and removed populating the GUID array from a fileexists routine.

#include <Array.au3>

$pc = InputBox("Compare Altiris Installs", "Please enter the asset tag of the machine to connect to.")
$dir1 = "C:\test"
$dir2 = "C:\test"

Dim $Dir1app[1]

Dim $Dir2app[1]


Local $appID[4]
$appID[0] = "Office 2007"
$appID[1] = "Visio Pro"
$appID[2] = "Adobe Reader"
$appID[3] = "Adobe Flash Player"


Local $appGUID[4]
$appGUID[0] = "{36bb7203-c642-4e06-92cb-1dc82bf21357}"
$appGUID[1] = "{2c33b47f-9efd-4d5a-a7a0-74ec7b4c321d}"
$appGUID[2] = "{ef1364d6-76be-4fad-9790-faa534baa9ba}"
$appGUID[3] = "{daab71ce-066d-4fb9-b83a-8d6458b7110b}"


For $element in $appID
  If Not FileExists($dir1 & $element) Then
   _ArrayAdd($Dir1app, $element)
   $rows = UBound($Dir1app)
   ReDim $Dir1app[$rows]
  EndIf
Next

Dim $Dir1GUID = $appGUID

For $element in $appID
  If Not FileExists($dir1 & $element) Then
   _ArrayAdd($Dir2app, $element)
   $rows = UBound($Dir2app)
   ReDim $Dir2app[$rows]
  EndIf
Next

Dim $Dir2GUID = $appGUID


_ArrayDelete($Dir1app , 0)
_ArrayDelete($Dir2app , 0)


_ArrayDisplay($Dir1app, "DIR 1 APPs")
_ArrayDisplay($Dir1GUID, "DIR 1 GUIDs")
_ArrayDisplay($Dir2app, "DIR 2 APPs")
_ArrayDisplay($Dir2GUID, "DIR 2 GUIDs")

for $s = 0 to ubound ($Dir1app) -1
    $search = _ArraySearch ($Dir2app , $Dir1app[$s])
    If @Error = 6 Then
        msgbox (0 , '' ,$Dir1app[$s] &  " was not found")
        else
msgbox (0 , '' , $Dir1GUID[$s] & " Commonly known as " & $Dir1app[$s] & " was found at index " & $search)
Endif
    Next
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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