Sign in to follow this  
Followers 0
jabbadahutt

FileReadLine - Error Allocating Memory

3 posts in this topic

Hi,

I am new to AutoIT and this is the first time I have made a post so apologies if it isn't correct.

Problem

I have had this a couple of times now, when using FileReadLine to read in the contents of a text file. The text file is only 59kb in size and holds the output from a Net View command. The problem (Error Allocating Memory) occurs when executed in a While loop. Has anyone any ideas?

A snapshot of the code is below.....

RunWait("h:\DomList.bat" ,"",@SW_HIDE)

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - Net view has run!")

$strFile = FileOpen($strDomainList, 0)

While 1

$strLine = FileReadLine($strFile)

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - $strLine is:" & $strLine)

If StringInStr($strLine, "\\SVR") Then

$intCharSpaceCount = 0

$intCharCount = 1

$intClientNameFound = 0

While $intClientNameFound <> 1

If StringMid($strLine, $intCharCount, 1) = " " Then

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - Character is a space!")

$intCharSpaceCount = $intCharSpaceCount + 1

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - Space count is:" & $intCharSpaceCount)

If $intCharSpaceCount >= 2 Then

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - Space count is:" & $intCharSpaceCount)

$intSvrNameEndsAt = $intCharCount - 2

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - $intSvrNameEndsAt is:" & $intSvrNameEndsAt)

$strClient = StringMid($strLine,3,($intSvrNameEndsAt - 2))

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - $strClient is:" & $strClient)

$intClientNameFound = 1

ExitLoop

Else

EndIf

Else

EndIf

$intCharCount = $intCharCount + 1

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - $intCharCount is:" & $intCharCount)

WEnd

$intCharCount = 0

$intCharSpaceCount = 0

$intSvrNameEndsAt = 0

ToolTip("Checking " & $strClient, 0, 0)

$strDatVer = RegRead("\\" & $strClient & "\HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\TVD\VirusScan Enterprise\CurrentVersion", "szVirDefVer")

$strDatDate = RegRead("\\" & $strClient & "\HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\TVD\VirusScan Enterprise\CurrentVersion", "szVirDefDate")

$strText = $strClient & "," & $strDatVer & "," & $strDatDate & @CRLF

OutputToLog($strFileName, $strText)

$strText = ""

$strDatVer = ""

$strDatDate = ""

$strClient = ""

$intClientCount = $intClientCount + 1

$strText = $strClient & "," & $strDatVer & "," & $strDatDate & @CRLF

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - Data should be null!:" & $strText)

Else

EndIf

If @error = -1 Then ExitLoop

Wend

msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - End of program, " & $intClientCount & " clients scanned!")

Func OutputToLog($strFileName, $strText)

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - Entered OutputToLog" & @CRLF & @CRLF & "$strFile is:" & $strFile & @CRLF & "$strText is:" & $strText)

$file = FileOpen($strFileName, 1)

FileWrite($file, $strText)

FileClose($file)

$strText = ""

;msgbox(0,"Debug Info","L" & @ScriptLineNumber & " - Check Output Log")

EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't know reason for memory allocation error but:

- for reading file use FileRead() and StringSplit() and FOR NEXT loop

- for getting NET VIEW result look at my NET Send GUI wrapper function LoadComputers(): http://www.autoitscript.com/forum/index.ph...st&p=343332

EDIT: corrected link

Edited by Zedna

Share this post


Link to post
Share on other sites

I don't know reason for memory allocation error but:

- for reading file use FileRead() and StringSplit() and FOR NEXT loop

- for getting NET VIEW result look at my NET Send GUI wrapper function LoadComputers(): http://www.autoitscript.com/forum/index.php?s=&showtopic=46016&view=findpost&p=343332

Thanks Zedna, I will try that ASAP. Have had a quick look at your code, its interesting to see how many different ways there are to do things. Thanks, will let you know how it works.

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