Chimaera Posted September 23, 2015 Posted September 23, 2015 I was adding some logging to one of my programs but ive hit a snagthe loop is like this and it just goes through an array of items to removeFor $TaskLoop = 1 To $aSchTaskNames[0] Local $sSchTask = RunWait(@ComSpec & ' /c ' & 'schtasks.exe' & ' /delete /tn ' & '"' & $aSchTaskNames[$TaskLoop] & '"' & ' /f ', '', @SW_HIDE) ;~ ConsoleWrite( $aSchTaskNames[$TaskLoop] & @CRLF) If @error < 0 Then ContinueLoop ElseIf $sSchTask >= 0 Then ConsoleWrite( '>0 ' & @error & @CRLF) FileWrite(@ScriptDir & '\errorlog.txt', @CRLF & @UserName & ' - ' & $aSchTaskNames[$TaskLoop]) ; create txt error log ContinueLoop EndIf NextThe problem is it writes every item in the array to the log.. I only want it to write the entry when it removes one from the machineIve tried it this way as wellFor $TaskLoop = 1 To $aSchTaskNames[0] RunWait(@ComSpec & ' /c ' & 'schtasks.exe' & ' /delete /tn ' & '"' & $aSchTaskNames[$TaskLoop] & '"' & ' /f ', '', @SW_HIDE) ;~ ConsoleWrite( $aSchTaskNames[$TaskLoop] & @CRLF) If @error < 0 Then ;~ ConsoleWrite( '<0 ' & @error & @CRLF) ContinueLoop ElseIf @error > 0 Then ;~ ConsoleWrite( '>0 ' & @error & @CRLF) FileWrite(@ScriptDir & '\errorlog.txt', @CRLF & @UserName & ' - ' & $aSchTaskNames[$TaskLoop]) ; create txt error log ContinueLoop EndIf NextI think the problem lies with the Runwait as it doesnt give a defined exit and it can often be 0 which doesnt help at allIs there a way to solve this so the log only triggers when it removes something? If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices()
JohnOne Posted September 23, 2015 Posted September 23, 2015 0 is generally considered good, the task completed successfully.You should write to error log if $sSchTask <> 0 Or @error <> 0 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
water Posted September 23, 2015 Posted September 23, 2015 I would use a two-step approach. First check for errors returned by RunWait. Then check the return value for the value that denotes a correct execution. This value is being taken from the array: Global $aSchTaskNames[][] = [[2, 2], ["Task1", 0], ["DOK", 0]] ; First task should return value 0, the second 0 For $TaskLoop = 1 To $aSchTaskNames[0][0] Local $iSchTask = RunWait(@ComSpec & ' /c ' & 'schtasks.exe' & ' /delete /tn ' & '"' & $aSchTaskNames[$TaskLoop][0] & '"' & ' /f ', '', @SW_HIDE) If @error <> 0 Then FileWriteLine(@ScriptDir & '\errorlog.txt', @UserName & ' - ' & $aSchTaskNames[$TaskLoop][0] & ': RunWait encountered error ' & @error) ; RunWait encounterd an error ElseIf $iSchTask <> $aSchTaskNames[$TaskLoop][1] Then FileWriteLine(@ScriptDir & '\errorlog.txt', @UserName & ' - ' & $aSchTaskNames[$TaskLoop][0] & ': Execution returned unexpected return value of ' & $iSchTask) ; The task returned an unexpected return value EndIf Next My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now