Sign in to follow this  
Followers 0
treyb

Error with While loop?

8 posts in this topic

Below is the code that I need help on. The scripts opens the .txt file and then reads each line comparing it the the active username. If the username is on the naughtyuser list, it will then email the details to the admins. When I leave out the email sending If statements the while loops works just fine. When I put it back in I get: "test1.au3 (40) : ==> "Wend" statement with no matching "While" statement.: Wend"

can anyone help me fix this?

#include <INet.au3>


$file = FileOpen("c:\AT_naughtyuser.txt", 0)
$time = "On: " & @MON & "-" & @MDAY & "-" & @YEAR & "  at: " & @hour & ":" & @MIN

If $file = -1 Then
    Exit
EndIf

While 1
    $curline = FileReadLine($file)
    
    If @error = -1 Then ExitLoop
    $line = $curline
    if(@UserName = $line) Then
        $From = "email@server.com"
        $To = "email@server.com"
        $subject = "Login Detected: " & @UserName
        $body = "Login Detected: Username: " & @UserName  & " Workstation: " & @ComputerName  & " Time: " & $time 
        $Username = "myemail@server.com"
        $Password = "mypassword" 
        $Response = _INetSmtpMail ($From, $to, $subject, $body, $Username, $Password) 
        $err = @error
        If $Response = 1 Then
            MsgBox(0, "Success!", "Mail sent")
        Else
            MsgBox(0, "Error!", "Mail failed with error code " & $err)
        EndIf
    ElseIf
Wend

FileClose($file)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Check Line 30 you are using ElseIf when it should be EndIf. Also I would recommend using the Full Version of SciTE4AutoIt3. :)

Plus, have a look at _FileReadToArray() in the Help File too.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Check Line 30 you are using ElseIf when it should be EndIf. Also I would recommend using the Full Version of SciTE4AutoIt3. :)

Plus, have a look at _FileReadToArray() in the Help File too.

DOH!!!!! I can not believe I missed that. I have been staring at it all day and couldn't see it.

Now I am getting error code of 3 when I try to mail. What does that mean? and is there a page that has all the error codes on it?

Share this post


Link to post
Share on other sites

DOH!!!!! I can not believe I missed that. I have been staring at it all day and couldn't see it.

Now I am getting error code of 3 when I try to mail. What does that mean? and is there a page that has all the error codes on it?

It means it was unable to resolve the IP. You can get the error codes as well as examples and sintaxis of the functions in the Autoit Helpfile that comes with Scite4 More Info here: http://www.autoitscript.com/autoit3/scite/

Share this post


Link to post
Share on other sites

Now I am getting error code of 3 when I try to mail. What does that mean? and is there a page that has all the error codes on it?

Hi and Welcome to the forum!

Open the helpfile and look at _INetSmtpMail()... What do you see?

1 - Invalid Parameters

2 - Unable to start TCP

3 - Unable to resolve IP

4 - Unable to create socket

5x - Cannot open SMTP session. x indicates the index number of last command issued to the SMTP server.

50x - Cannot send body. x indicates the line number of $as_Body (first line is 0).

5000 - Cannot close SMTP session

So what happens is "Unable to resolve IP".

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It means it was unable to resolve the IP. You can get the error codes as well as examples and sintaxis of the functions in the Autoit Helpfile that comes with Scite4 More Info here: http://www.autoitscript.com/autoit3/scite/

No no no. There's no AutoIt stuff in the SciTE package. You get the AutoIt helpfile with AutoIt.

But SciTE4AutoIt3 should of course be installed anyway. Fir the SciTE stuff.

Edit: And don't call it SciTE4, that's just confusing.

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

No no no. There's no AutoIt stuff in the SciTE package. You get the AutoIt helpfile with AutoIt.

But SciTE4AutoIt3 should of course be installed anyway. Fir the SciTE stuff.

Edit: And don't call it SciTE4, that's just confusing.

Yep, you got a point there, the documentation he asked for comes with AutoIt. SciTE4Autoit is an editor in which is very easy to access to the helpfile among other things -like it predicts the functions you're going to use- that's why I got confused.

Anyway, here is the online help (it doesn't seem to have the user defined functions though): http://www.autoitscript.com/autoit3/docs/

And in case the OP doesn't have the helpfile for some reason (that was my first impression) : http://www.autoitscript.com/autoit3/downloads.shtml

Share this post


Link to post
Share on other sites

Got it fixed. changed it from email to Smtp Server and it magically started working :) Thanx for all your help. The error code helped narrow it down alot.

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