Sign in to follow this  
Followers 0
myk3

Compare array

8 posts in this topic

For some reason i am having a brain fart and can't think of how to complete this

I need to find software on systems that are above the baseline.. for example the baseline does not include "visio" but this system has it on it..

I currently have a script that scan the uninstall string in the reg and outputs the values to an excel doc.

However I need to compare that list to the "baseline" list..

here is what i currently have..

#include <Excel.au3>
#include <Array.au3>
#include <file.au3>
#include <ad.au3>
#include <GuiListView.au3>
#RequireAdmin
_AD_Open()
;****************************************************************
;~ Pull items from OU
;****************************************************************
Global $aComputers
if FileExists (@scriptdir & "\OU.txt") Then
    $sOU = FileReadLine (@scriptdir & "\OU.txt",1)
Else
    FileOpen (@scriptdir & "\OU.txt",1)
$sOU =  InputBox("OU?","What is your OU's Distinguidhed Name?","","",250,125)
FileWriteLine (@scriptdir & "\OU.txt",$sOU)
FileClose(@scriptdir & "\OU.txt")
If  @error then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
elseif $sOU = "" then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
endif
endif
$aComputers = _AD_GetObjectsInOU($sOU,"(objectcategory=computer)",2,"name,location") ;calls function in the AD.au3 to query AD
_AD_Close()

$1 =1
Global $i
Local $sSft
ProgressOn("Progress", "Start Scan","")
$oExcel2 = _ExcelBookNew(0)
Do
ProgressSet(($1 / UBound($aComputers)*100),"Scanning " & $1 & " of " & UBound($aComputers)-1 & " " & $aComputers[$1][0],StringFormat("%.2f", ($1 / UBound($aComputers)*100)) & "% Complete")
$var = Ping($aComputers[$1][0])
if $var Then
_ComputerGetSoftware($sSft)
_ExcelSheetAddNew($oExcel2,$aComputers[$1][0])
_ExcelSheetActivate($oExcel2,$aComputers[$1][0])
_ExcelWriteSheetFromArray($oExcel2, $sSft,1,1,1,0)
_ExcelBookSaveAs($oExcel2, @scriptdir & "\Installed Software" , "xls", 0, 1)
$1+=1
Else
_ExcelSheetAddNew($oExcel2,$aComputers[$1][0])
_ExcelSheetActivate($oExcel2,$aComputers[$1][0])
_ExcelWriteCell($oExcel2,"Unable to Ping",1,1)
_ExcelBookSaveAs($oExcel2, @scriptdir & "\Installed Software" , "xls", 0, 1)
$1+=1
EndIf
Until $1 = UBound($aComputers)
_ExcelBookClose($oExcel2)

Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
    Local Const $UnInstKey = "\\" & $aComputers[$1][0] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $i = 1
    Dim $aSoftwareInfo[1][4]
    For $j = 1 To 500
        $AppKey = RegEnumKey($UnInstKey, $j)
        If @error <> 0 Then Exitloop
        If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
        ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4]
        $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
        $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
        $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
        $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3)
        $i = $i + 1
    Next
    $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
    If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0)      
    Return _ArraySort($aSoftwareInfo)
EndFunc

Share this post


Link to post
Share on other sites



I am making progress.. Now I just need to figure out the array search function

Share this post


Link to post
Share on other sites

Ok I think I got it..

Can someone explain to me how to call just a row of a array?

the array is 4 columns wide..

Michael

Share this post


Link to post
Share on other sites

For $i=1 to UBound($array)

MsgBox(0,"",$array[$i][1][1][1])

Next

is a basic example of how you could set it up.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For $i=1 to UBound($array)

MsgBox(0,"",$array[$i][1][1][1])

Next

is a basic example of how you could set it up.

For some reason I can not get it.. here is my code..

#include <Excel.au3>
#include <Array.au3>
#include <file.au3>
#include <ad.au3>
#include <GuiListView.au3>
#RequireAdmin
_AD_Open()
;****************************************************************
;~ Pull items from OU
;****************************************************************
Global $aComputers
if FileExists (@scriptdir & "\OU.txt") Then
    $sOU = FileReadLine (@scriptdir & "\OU.txt",1)
Else
    FileOpen (@scriptdir & "\OU.txt",1)
$sOU =  InputBox("OU?","What is your OU's Distinguidhed Name?","","",250,125)
FileWriteLine (@scriptdir & "\OU.txt",$sOU)
FileClose(@scriptdir & "\OU.txt")
If  @error then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
elseif $sOU = "" then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
endif
endif
$aComputers = _AD_GetObjectsInOU($sOU,"(objectcategory=computer)",2,"name,location") ;calls function in the AD.au3 to query AD
_AD_Close()

$oExcel =_ExcelBookOpen(@ScriptDir & "\baseline.xls",0)
$test = _ExcelReadSheetToArray($oExcel)
_ExcelBookClose($oExcel)

$1 =1
$s =1
Global $i
Local $sSft
ProgressOn("Progress", "Start Scan","")
$oExcel2 = _ExcelBookNew(0)
Do
ProgressSet(($1 / UBound($aComputers)*100),"Scanning " & $1 & " of " & UBound($aComputers)-1 & " " & $aComputers[$1][0],StringFormat("%.2f", ($1 / UBound($aComputers)*100)) & "% Complete")
$var = Ping($aComputers[$1][0])
if $var Then
_ComputerGetSoftware($sSft)
_ExcelSheetAddNew($oExcel2,$aComputers[$1][0])
_ExcelSheetActivate($oExcel2,$aComputers[$1][0])
;~ _ExcelWriteSheetFromArray($oExcel2, $sSft,1,1,1,0)
;~ _ArrayDisplay($test)
;~ _ArrayDisplay($sSft)

for $s=1 to UBound($sSft)
$string = $sSft[$s][1][1][1]
_ArraySearch($test,$string)
if @error = 1 Then
_ExcelWriteCell($oExcel2,$string,0,1)
endif
$s += 1
next


_ExcelBookSaveAs($oExcel2, @scriptdir & "\Installed Software" , "xls", 0, 1)
$1+=1
Else
_ExcelSheetAddNew($oExcel2,$aComputers[$1][0])
_ExcelSheetActivate($oExcel2,$aComputers[$1][0])
_ExcelWriteCell($oExcel2,"Unable to Ping",1,1)
_ExcelBookSaveAs($oExcel2, @scriptdir & "\Installed Software" , "xls", 0, 1)
$1+=1
EndIf
Until $1 = UBound($aComputers)
_ExcelBookClose($oExcel2)

Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
    Local Const $UnInstKey = "\\" & $aComputers[$1][0] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $i = 1
    Dim $aSoftwareInfo[1][4]
    For $j = 1 To 500
        $AppKey = RegEnumKey($UnInstKey, $j)
        If @error <> 0 Then Exitloop
        If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
        ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4]
        $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
        $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
        $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
        $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3)
        $i = $i + 1
    Next
    $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
    If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0)      
    Return _ArraySort($aSoftwareInfo)
EndFunc

Here is an example of the array I am trying to read the row of.

Posted Image

Edited by myk3

Share this post


Link to post
Share on other sites

This will generate the software listing, then loop through the array one row at a time....

#include <GuiListView.au3>
#include <Array.au3>

Local $sSft
_ComputerGetSoftware($sSft)

_ArrayDisplay ($sSft)

for $i = 1 to ubound ($sSFT) - 1
    Local $row[1][4]
    $row[0][0] = $sSft[$i][0]
    $row[0][1] = $sSft[$i][1]
    $row[0][2] = $sSft[$i][2]
    $row[0][3] = $sSft[$i][3]
_ArrayDisplay ($row)
next

; Author JSThePatriot - Modified June 20, 2010 by ripdad
Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
    Local Const $UnInstKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $i = 1
    Dim $aSoftwareInfo[1][4]

    For $j = 1 To 500
        $AppKey = RegEnumKey($UnInstKey, $j)
        If @error <> 0 Then Exitloop
        If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
        ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4]
        $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
        $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
        $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
        $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3)
        $i = $i + 1

    Next
    $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
    If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0)
    Return _ArraySort($aSoftwareInfo)


EndFunc

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks dude.. I will check it out tomorrow when I get to work..

Edited by myk3

Share this post


Link to post
Share on other sites

This will generate the software listing, then loop through the array one row at a time....

This worked however no I have a new problem..

Everything works fine but around systems number 18 it fails to create a new excel sheet and activate it..

It fails around line 61, but again only on a few systems..

#include <Excel.au3>
#include <Array.au3>
#include <file.au3>
#include <ad.au3>
#include <GuiListView.au3>
#RequireAdmin
_AD_Open()
;****************************************************************
;~ Pull items from OU
;****************************************************************
Global $aComputers
if FileExists (@scriptdir & "\OU.txt") Then
    $sOU = FileReadLine (@scriptdir & "\OU.txt",1)
Else
    FileOpen (@scriptdir & "\OU.txt",1)
$sOU =  InputBox("OU?","What is your OU's Distinguidhed Name?","","",250,125)
FileWriteLine (@scriptdir & "\OU.txt",$sOU)
FileClose(@scriptdir & "\OU.txt")
If  @error then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
elseif $sOU = "" then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
endif
endif
$aComputers = _AD_GetObjectsInOU($sOU,"(objectcategory=computer)",2,"name,location") ;calls function in the AD.au3 to query AD
_AD_Close()

if FileExists (@scriptdir & "\Installed Software.xls") Then
    FileDelete(@scriptdir & "\Installed Software.xls")
EndIf
if FileExists (@scriptdir & "\Installed Software Dump.xls") Then
    FileDelete(@scriptdir & "\Installed Software Dump.xls")
EndIf;

$oExcel5 = _ExcelBookOpen(@ScriptDir & "\baseline\XP.xls",0)
$oExcel6 = _ExcelBookOpen(@ScriptDir & "\baseline\Vista.xls",0)
$oExcel7 = _ExcelBookOpen(@ScriptDir & "\baseline\7.xls",0)
$xp = _ExcelReadSheetToArray($oExcel5)
$vista = _ExcelReadSheetToArray($oExcel6)
$7 = _ExcelReadSheetToArray($oExcel7)
_ExcelBookClose($oExcel5)
_ExcelBookClose($oExcel6)
_ExcelBookClose($oExcel7)

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$1 =1
Global $i
Local $sSft
ProgressOn("Progress", "Start Scan","")
$oExcel2 = _ExcelBookNew(0)
$oExcel3 = _ExcelBookNew(0)
Do
ProgressSet(($1 / UBound($aComputers)*100),"Scanning " & $1 & " of " & UBound($aComputers)-1 & " " & $aComputers[$1][0],StringFormat("%.2f", ($1 / UBound($aComputers)*100)) & "% Complete")
$var = Ping($aComputers[$1][0])
if $var Then

_ComputerGetSoftware($sSft)
_ExcelSheetAddNew($oExcel2,$aComputers[$1][0])
_ExcelSheetActivate($oExcel2,$aComputers[$1][0])
_ExcelSheetAddNew($oExcel3,$aComputers[$1][0]);Dump
_ExcelSheetActivate($oExcel3,$aComputers[$1][0]);Dump
_ExcelWriteSheetFromArray($oExcel3, $sSft,1,1,1,0);Dump
$s = 1
$w = 1
$objWMI = ObjGet("winmgmts:\\"&  $aComputers[$1][0] &"\root\CIMV2")
if @error Then
$HexNumber=hex(@Error,8) 
_ExcelWriteCell($oExcel2,"ERROR",$s,1)
_ExcelWriteCell($oExcel2,$HexNumber,$s,2)
_ExcelWriteCell($oExcel3,"ERROR",$s,1)
_ExcelWriteCell($oExcel3,$HexNumber,$s,2)
ContinueLoop
EndIf
$objOS = $objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($objOS) Then
For $objItem in $objOS
$OS = $objItem.Version
next
EndIf
        
if $OS = "6.0.6002" Then
    $test = $vista
elseif $OS = "6.1.7600" Then
    $test = $7
elseif $OS = "5.1.2600" Then
    $test = $xp
EndIf

for $p = 1 to ubound ($sSft) - 1
    $search = $sSft[$p][0]
    $search1 = $sSft[$p][1]
    $search2 = $sSft[$p][2]
    $search3 = $sSft[$p][3]
_ArraySearch($test,$search)
if @error Then
_ExcelWriteCell($oExcel2,$search,$s,1)
_ExcelWriteCell($oExcel2,$search1,$s,2)
_ExcelWriteCell($oExcel2,$search2,$s,3)
_ExcelWriteCell($oExcel2,$search3,$s,4)
$s += 1
$w += 1
endif
next
_ExcelBookSaveAs($oExcel3, @scriptdir & "\Installed Software Dump" , "xls", 0, 1)
_ExcelBookSaveAs($oExcel2, @scriptdir & "\Installed Software" , "xls", 0, 1)
$1+=1
Else
_ExcelSheetAddNew($oExcel2,$aComputers[$1][0])
_ExcelSheetActivate($oExcel2,$aComputers[$1][0])
_ExcelWriteCell($oExcel2,"Unable to Ping",1,1)
_ExcelBookSaveAs($oExcel3, @scriptdir & "\Installed Software Dump" , "xls", 0, 1)
_ExcelBookSaveAs($oExcel2, @scriptdir & "\Installed Software" , "xls", 0, 1)
$1+=1
EndIf
Until $1 = UBound($aComputers)
_ExcelBookClose($oExcel2)
_ExcelBookClose($oExcel3)
Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
    Local Const $UnInstKey = "\\" & $aComputers[$1][0] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $i = 1
    Dim $aSoftwareInfo[1][4]
    For $j = 1 To 500
        $AppKey = RegEnumKey($UnInstKey, $j)
        If @error <> 0 Then Exitloop
        If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
        ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4]
        $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
        $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
        $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
        $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3)
        $i = $i + 1
    Next
    $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
    If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0)      
    Return _ArraySort($aSoftwareInfo)
EndFunc

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