Sign in to follow this  
Followers 0
myk3

function output when = "0" / NULL

2 posts in this topic

#1 ·  Posted (edited)

I am trying to scan a remote systems uninstall registry and paste this value to a excel.. Everything is working except if I am unable to login to the remote system it just passes it and doesn't write anything out.. I am unable to find in the script for the non-connections.. I have already placed a if ping then and if not ping then but this doesn't account for if the ping is good but I am unable to login..

#include <Excel.au3>
#include <Array.au3>
#include <file.au3>
#include <ad.au3>
#include <GuiListView.au3>
#RequireAdmin
_AD_Open()

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")
_AD_Close()
$1=1
;~ _ArrayDisplay($aComputers)
Global $i
Local $sSft
ProgressOn("Progress", "Start Scan","")

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)
if $sSft = 0 Then
MsgBox(0,"","$sSft = 0"
    $1+=1
Else
$oExcel2 = _ExcelBookNew(0)
_ExcelWriteSheetFromArray($oExcel2, $sSft,1,1,1,0)
_ExcelBookSaveAs($oExcel2, @scriptdir & "\InstalledSoftware\"& $aComputers[$1][0] , "xls", 0, 1)
_ExcelBookClose($oExcel2, 0)
$1+=1
endif

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

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)    
    $1+=1
    Return _ArraySort($aSoftwareInfo)
EndFunc

EDIT : Example I am scanning my OU and when it completes I only have 80 excel docs.. 15 are no pings and the rest are full scans.. The problem is I have 140 items in the OU..

Edited by myk3

Share this post


Link to post
Share on other sites



I got everything working.. Thanks

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