Code Error 800A041F – Unexpected ‘Next’

Troubleshooting Code 800A041F – Unexpected ‘Next’

Introduction to Error Code 800A041F

This error code, 800A041F occurs when you execute a VBScript with a loop.  My suggestion is that there is missing End or End If statement.Code Error 800A041F - Unexpected 'Next'

The Symptoms You Get 800A041F

The script does not execute as you hoped, instead you get a WSH error message.

The Cause of Error 800A041F

The underlying cause is a syntax error, in the sense that you are missing an ‘End If’ statement.  In my example, the error is blamed on Line: 23, however the problem occurs earlier in the script.  An examination of the statement: ‘If objUser.class="user"’ then, reveals that there is no valid ‘End If‘ statement.

The Solution

This error message is caused by a mixture of logic and syntax.  If you focus on the word ‘Unexpected’ then you get a valuable clue.  Incidentally, I first read the Error: as ‘Expected’ instead of ‘Unexpected’, this mistake set me back half an hour.

VBScript’s ‘Next’ statement is present, but it comes too soon, the ‘End IF’ is missing.  In your script, check each ‘If’, and ‘Else If’ statement, what you are looking for is a missing End If command.

  ‡

Example of Error 800A041F Script

The actual problem is not with the For …. Next loop, but with the inner loop: If.. Then.  What is needed is an ‘End If’.  Close study reveals that the ‘End If’ has been ‘Remmed out and that is why the script fails. 

 

‘ Set AccountControl.vbs
‘ Example VBScript to enable user accounts in a named OU
‘ Author Guy Thomas https://computerperformance.co.uk/
‘ Version 1.7 – March 21st 2010
‘ —————————————————-‘
Option Explicit
Dim objOU, objUser, objRootDSE
Dim strContainer, strLastUser, strDNSDomain, intCounter, intAccValue
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = "OU=Cowbridge ,"
intAccValue = 512
strContainer = strContainer & strDNSDomain
set objOU =GetObject("LDAP://" & strContainer )
intCounter = 0
For each objUser in objOU
    If objUser.class="user" then
    objUser.Put "userAccountControl", intAccValue
    objUser.SetInfo
    intCounter = intCounter +1
    strLastUser = objUser.Get ("name")
    ‘ End if
next
WScript.Echo intCounter & " Accounts Enabled. Value " _
& intAccValue
WScript.Quit
‘ End of VBScript Example

 

Corrected Version

‘ Set AccountControl.vbs
‘ Example VBScript to enable user accounts in a named OU
‘ Author Guy Thomas https://computerperformance.co.uk/
‘ Version 1.7 – March 21st 2010
‘ —————————————————-‘
Option Explicit
Dim objOU, objUser, objRootDSE
Dim strContainer, strLastUser, strDNSDomain, intCounter, intAccValue
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = "OU=Cowbridge ,"
intAccValue = 512
strContainer = strContainer & strDNSDomain
set objOU =GetObject("LDAP://" & strContainer )
intCounter = 0
For each objUser in objOU
     If objUser.class="user" then
     objUser.Put "userAccountControl", intAccValue
     objUser.SetInfo
     intCounter = intCounter +1
     strLastUser = objUser.Get ("name")
     End if
next
WScript.Echo intCounter & " Accounts Enabled. Value " _
& intAccValue
WScript.Quit

‘ End of VBScript Example

 

See More Windows Update Error Codes 8004 Series

Error 800A101A8 Object Required   •Error 800A0046   •Error 800A10AD   •Error 800A000D

Error 80048820   •Error 800A0401   •Review of SolarWinds Permissions Monitor

Error 80040E14   • Error 800A03EA   • Error 800A0408   • Error 800A03EE

Solarwinds Free WMI MonitorGuy Recommends: WMI Monitor and It’s Free!

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.  Fortunately, SolarWinds have created the WMI Monitor so that you can examine these gems of performance information for free.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor


Do you need additional help?

Give something back?

Would you like to help others?  If you have a good example of this error, then please email me, I will publish it with a credit to you:

 

If you like this page then please share it with your friends