Jump to content

Fresh set of eyes? Loop not incrementing..


Recommended Posts

I can't seem to figure out why all of a sudden the $var1 isn't going to the next line of the file when it loops. $var1 is in red in the code here. It was working earlier but some other stuff wasn't. Only thing I really changed was how I opened that file and stated that it was $var1. Was necessary since all of a sudden it was telling me that I was using an invalid file handle at that same spot (come to think of it)...

Anyway, been tinkering with this stuff for too long. It seems to be VERY addictive. This could be a problem..

Ok, seems to not want to let me add color to the code so it's the line just inside the While 1 that says

$var1 = FileReadLine($mfile)

everytime I loop around it "should" go to the next line. I don't see where I'm closing it anywhere.. Perhaps a beer would help?

#include <_Trentlib.au3>
#include <Process.au3>


    $ofile = ("Outputfile.txt")
    GatherComp()
    CreateVars() 
    

Func GatherComp()  ;exports all computer objects from within AD that have Professional in their OS Name to a file named MYMACHINES.txt
;MsgBox(0, "Run GatherComp Func?:", "You have entered the GatherComp function")
    $sCmd2Run = "logparser ""SELECT cn INTO MYMACHINES.txt FROM ""LDAP://sleh.com/DC=MY,DC=COM"" WHERE operatingSystem LIKE '%Professional%'"" -i:ADS -objClass:computer -o:TSV -headers:off -filemode:1"
    $sErrorStatus = RunWait($sCmd2Run, @ScriptDir, @SW_HIDE)
;MsgBox(0, "Error Status", "Error Status = '" & $sErrorStatus & "'")
EndFunc

Func CreateVars();gathers the image type and IPAddress of each computer that was gathered by GatherComp Function
            ;-----------------------------------------------------------------------------------------------------------------------
    ;Opens MYMACHINES.txt for reading. If the file does not exist then it will return out of the function
        $mfile = ( "MYMACHINES.txt" )
        FileOpen($mfile, 0)
        If $mfile = -1 Then Return
    ;-----------------------------------------------------------------------------------------------------------------------    
    While 1
        MsgBox(0, "Start Loop", "At beginning")
        $var1 = FileReadLine($mfile)
        MsgBox(0, "Var1=", $var1)
        If @error = -1 Then
            FileClose ($mfile)
            ExitLoop
        EndIf
        $pingit = "alive /Repeat=3 /Timeout=1 " & $var1
        $rc = _RunDos($pingit)

        If $rc = 0 Then
            $sCmd2Run = 'alive ' & $var1 & ' > getip.txt '
            _RunDOS($sCmd2Run)
        ;_Runtest($sCmd2Run)
            $ip = FileOpen ("getip.txt", 0)
            $ip = FileReadLine ("getip.txt", 3)
            FileClose ( $ip )
            $String = StringSplit ( $ip, "(" & ")") 
            $var2 = $String[2] 
            FileDelete ("getip.txt")
            MsgBox(0, "IP Address", $var2)
            FileOpen($ofile, 1)
            FileWriteLine ($ofile,$var1 & "," & $var2)
            FileClose($ofile)
        Else    
            $var2 = ""
            FileOpen($ofile, 1)
            FileWriteLine ($ofile,$var1 & "," & $var2)
            FileClose($ofile)
            MsgBox(0, "Looping Now?", "at end")
        EndIf
    WEnd
EndFunc
Link to comment
Share on other sites

maybe try

$cnt = 0

While 1
$cnt = $cnt + 1
$var1 = FileReadLine($mfile, $cnt)

..........

8)

EDIT....

also you need to remove this message box or it wont get/check the error ( If @error = -1 Then )

MsgBox(0, "Var1=", $var1)

Edited by Valuater

NEWHeader1.png

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