kor Posted July 24, 2014 Share Posted July 24, 2014 I am getting this error in my compiled script, but the same script when running from scite I don't see the problem. It reports the line number as 9,085 but my script is only about 100 lines of code. Since this only seems to happen after I compile it can anyone offer some things I can look for that might help me troubleshoot. Any code examples of good error checking that I can build in so I can debug after it's compiled? Link to comment Share on other sites More sharing options...
water Posted July 24, 2014 Share Posted July 24, 2014 How should we help without seing your code? I lost my crystal ball last week My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
kor Posted July 24, 2014 Author Share Posted July 24, 2014 (edited) expandcollapse popup#AutoIt3Wrapper_Change2CUI=y ; allows you to output console to command window #include <AD.au3> #include <File.au3> #include <Array.au3> ; ##################################################################### ; ### Set Run Mode ### ; ### 0 = Production Mode [DEFAULT] ### ; ### 1 = Verbose Production Mode ### ; ### 2 = Logging Only ### ; ### 3 = Verbose Logging Only ### Global $iRunMode = 0 ; ### ; ### Set Production Mode ### ; ### 0 = All [DEFAULT] ### ; ### 1 = Teachers Only ### ; ### 2 = School Admins Only ### ; ### 3 = Departments Only ### Global $iRunSection = 1 ; ### ; ##################################################################### ; ########################################################################################################################################################################### ; ## DO NOT MODIFY SCRIPT BELOW THIS LINE ################################################################################################################################### ; ########################################################################################################################################################################### Global $sDepartmentQuery = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(!company=stu)(!(!company=*)))", _ ; LDAP Query | person, user, not disabled, not teacher, not student, company not null $sSchoolQuery = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(!company=admin)(!company=stu)(!(!company=*)))", _ ; LDAP Query | person, user, not disabled, not admin, not student, company not null $aUsers, $aDepartments, $aUserGroups, $sText, $sType, $aSchools, $aAdmins, $aTeachers, $aInput, $aAllOtherAdmins, $iRunMode, $hLogFile If @Compiled Then Switch $CmdLine[0] Case 0 ; if no arguments provided set defaults $iRunMode = 0 $iRunSection = 0 Case 1, 3 To 64 ; if too few or too many arguments ;_ConsoleHelp() Case 2 If StringRegExp($CmdLine[1], "[0-3]") > 0 And StringRegExp($CmdLine[2], "[0-3]") > 0 Then ; check command line options for valid arguments $iRunMode = $CmdLine[1] $iRunSection = $CmdLine[2] Else ;_ConsoleHelp() EndIf EndSwitch EndIf _AD_Open() ; open connection to Active Directory $hLogFile = FileOpen(@ScriptDir & "\GMAR-log.log", 10) ; create log file _VerboseLog("[VERBOSE] - Begin") Switch $iRunSection Case 0 ; all _Teachers() ;_Admins() ;_Departments() Case 1 ; teachers only _Teachers() Case 2 ; school admins only _Admins() Case 3 ; departments only _Departments() Case Else _Log("[ERROR] Unknown Production Mode") Exit(1) EndSwitch Func _Teachers() _Log("[INFO][BEGIN TEACHERS]") _Log("[INFO][Running Teacher LDAP Query]") $aUsers = _AD_GetObjectsInOU("", $sSchoolQuery, 2, "sAMAccountName,company,department,physicalDeliveryOfficeName,title", "") ; query AD (4.439s), not sorting to save 500ms ; $aUsers[$i][0] = sAMAccountName (username) ; $aUsers[$i][1] = company (TCH, Admin, Stu, Contractor) ; $aUsers[$i][2] = department ; $aUsers[$i][3] = physicalDeliveryOfficeName (site) ; $aUsers[$i][4] = title (job title) _Log("[INFO][Reading Schools INI Section]") $aSchools = IniReadSection(@ScriptDir & "\GMAR-settings.ini", "Schools") ; read ini file for list of schools _RemoveQuotes($aSchools) ; $aSchools[$i][0] = school number ; $aSchools[$i][1] = school group prefix _Log("[INFO][Reading Teachers INI Section]") $aTeachers = IniReadSection(@ScriptDir & "\GMAR-settings.ini", "Teachers") ; read ini file for teacher group name _RemoveQuotes($aTeachers) ; $aTeachers[$i][0] = company ; $aTeachers[$i][1] = group name _Log("[INFO][Running Add/Remove Checks]") _VerboseLog("[VERBOSE] - Teacher Array contains " & UBound($aUsers) - 1 & " objects") _VerboseLog("[VERBOSE] - School Array contains " & UBound($aSchools) - 1 & " objects") For $i = 1 To UBound($aUsers) - 1 ; loop for each teacher user _VerboseLog("[VERBOSE] - User " & $i & " - " & $aUsers[$i][0]) For $n = 1 to UBound($aSchools) - 1 ; loop for each school number If StringInStr($aUsers[$i][3], $aSchools[$n][0]) > 0 Then ; if teachers location matches school number If _AD_IsMemberOf($aSchools[$n][1] & " - " & $aTeachers[1][1], $aUsers[$i][0]) <> 1 Then ; if user is not already a member of the group _Log("[ADD] - " & $aUsers[$i][0] & " - [TO] - " & $aSchools[$n][1] & " - " & $aTeachers[1][1]) If $iRunMode < 2 Then _AD_AddUserToGroup($aSchools[$n][1] & " - " & $aTeachers[1][1], $aUsers[$i][0]) ; add user to group If @error Then _Log("[ERROR][ADD] - " & $aUsers[$i][0] & " - [TO] - " & $aSchools[$i][1] & " - " & $aTeachers[1][1]) EndIf Else _VerboseLog("[VERBOSE][SKIP] - " & $aUsers[$i][0] & " - [MEMBER] - " & $aSchools[$n][1] & " - " & $aTeachers[1][1]) EndIf ElseIf StringInStr($aUsers[$i][3], $aSchools[$n][0]) = 0 Then ; if teachers location does not match school number If _AD_IsMemberOf($aSchools[$n][1] & " - " & $aTeachers[1][1], $aUsers[$i][0]) = 1 Then ; if user is a member of the group _Log("[REMOVE] - " & $aUsers[$i][0] & " - [FROM] - " & $aSchools[$n][1] & " - " & $aTeachers[1][1]) If $iRunMode < 2 Then _AD_RemoveUserFromGroup($aSchools[$i][1] & " - " & $aTeachers[1][1], $aUsers[$i][0]) ; remove user to group If @error Then _Log("[ERROR][REMOVE] - " & $aUsers[$i][0] & " - [FROM] - " & $aSchools[$i][1] & " - " & $aTeachers[1][1]) EndIf Else _VerboseLog("[VERBOSE][SKIP] - " & $aUsers[$i][0] & " - [NOT MATCH] - " & $aSchools[$n][1] & " - " & $aTeachers[1][1]) EndIf EndIf Next Next _Log("[INFO][END TEACHERS]") EndFunc ;==>_Teachers Func _Log($sText = "") ; writes script output to console, command window is compiled, and file Select Case StringInStr($sText, "ERROR") > 0 $sPrefix = "! " ; red for error Case StringInStr($sText, "ADD") > 0 $sPrefix = "+ " ; blue for add Case StringInStr($sText, "REMOVE") > 0 $sPrefix = "- " ; orange for move Case Else $sPrefix = "> " ; blue for info EndSelect ConsoleWrite($sPrefix & $sText & @CRLF) _FileWriteLog($hLogFile, $sText) EndFunc ;==>_Log Func _VerboseLog($sText = "") ; writes script output to console, command window is compiled, and file If $iRunMode = 1 Or $iRunMode = 3 Then ConsoleWrite($sText & @CRLF) _FileWriteLog($hLogFile, $sText) EndIf EndFunc ;==>_Log Func _RemoveQuotes(ByRef $aInput) ; removes quotes from INI file just in case someone adds them For $i = 1 To UBound($aInput) - 1 $aInput[$i][0] = StringReplace($aInput[$i][0], '"', "") $aInput[$i][1] = StringReplace($aInput[$i][1], '"', "") Next EndFunc ;==>_RemoveQuotes _AD_Close() ; close connection to Active Directory FileClose($hLogFile) ; close log file _VerboseLog("[VERBOSE] - End") Edited July 24, 2014 by kor Link to comment Share on other sites More sharing options...
water Posted July 24, 2014 Share Posted July 24, 2014 Can you please tell us which version of AutoIt and the AD UDF you run? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
kor Posted July 24, 2014 Author Share Posted July 24, 2014 AutoIT 3.3.12.0 AD 1.4.1.0 Link to comment Share on other sites More sharing options...
water Posted July 24, 2014 Share Posted July 24, 2014 I would insert FileWriteLine("C:\temp\log.txt", "unique number or text") before each function accessing an array so you know where the script fails. Then in a second run write the used indices of this statement to the same file. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
kor Posted July 25, 2014 Author Share Posted July 25, 2014 I would insert FileWriteLine("C:\temp\log.txt", "unique number or text") before each function accessing an array so you know where the script fails. Then in a second run write the used indices of this statement to the same file. I lost you at the second sentence. Can you provide an example of what you mean by write the used indices? Link to comment Share on other sites More sharing options...
water Posted July 25, 2014 Share Posted July 25, 2014 This line accesses an array:If StringInStr($aUsers[$i][3], $aSchools[$n][0]) > 0 Then ; if teachers location matches school numberSo I would insert the FileWrite before this (and all other lines accessing an array):FileWriteLine("C:\temp\log.txt", "27") ; A unique number or text so you know where your script crashed If StringInStr($aUsers[$i][3], $aSchools[$n][0]) > 0 Then ; if teachers location matches school numberIf the last line written to the log is "27" you know where it crashed.Now add a new FileWrite line to log the relevant indexes:FileWriteLine("C:\temp\log.txt", "27") ; A unique number or text so you know where your script crashed FileWriteLine("C:\temp\log.txt", "$i: " & $i & ", $n: " & $n) ; All indices used in the next statement If StringInStr($aUsers[$i][3], $aSchools[$n][0]) > 0 Then ; if teachers location matches school numberNow you should have an idea what goes wrong. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
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