Code Error 80041021

Troubleshooting Code Error 80041021

Introduction to Code 80041021

Error code, 80041021 occurs when you execute a VBScript connecting to WMI (Windows Management Instrumentation).  A wild guess there is a missing \\ in the winmgmts statement.

The Symptoms You Get Error Code 80041021 WMI VBScript

The script does not manipulate the WMI object as you had hoped, instead you get a Windows Script Host error message like this picture:

The Cause of Code 80041021

Case 1

Your VBScript contains a misspelled object name.  Code 80041021 is an unusual Error in that a number is returned rather than ‘Syntax Error’ or other message.  In my example the fault was in a WMI script, the cause was a syntax error with Set objWMI = GetObject("winmgmts:"

Case 2

In another example, I had the reverse problem, I put:  \\ machinename in the string variable, whereas I should have used plain:  machinename.

Case 3

I removed the impersonationLevel=impersonate statement from the VBScript.

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set objWMIService = GetObject("winmgmts:" _
& strComputer & "\root\cimv2")

The Solutions

I solved this 80041021 error message by paying close attention to the line number.  In addition, I compared the scripts to other WMI examples.  In one case it turned out to be a missing \\ in Set objWMI = GetObject("winmgmts:\\"…..  In another case it was a missing & "{impersonationLevel=impersonate}!\\" _

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

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory or Exchange Server. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

Example of Code Error 80041021 Script

Mistake in Line 38

Set objWMI = GetObject("winmgmts:"


Set objWMI = GetObject("winmgmts:\\"

‘ EventID12.vbs
‘ Version 1.9
‘ Guy Thomas 1st August 2010

Option Explicit

Dim objFso, objFolder, objWMI, objEvent ‘ Objects
Dim strFile, strComputer, strFolder, strFileName, strPath ‘ Strings
Dim intEvent, intNumberID, intRecordNum, colLoggedEvents

‘ ——————————————–
‘ Set your variables
intNumberID = 12 ‘ Event ID Number
intEvent = 1
intRecordNum = 1

strComputer = "."
strFileName = "\Event12.txt"
strFolder = "C:\GuyEbooks"
strPath = strFolder & strFileName

‘ —————————————-
‘ Section to create folder to hold file.
Set objFso = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strFolder) Then
Set objFolder = objFSO.GetFolder(strFolder)
Set objFolder = objFSO.CreateFolder(strFolder)
Wscript.Echo "Folder created " & strFolder
End If
Set strFile = objFso.CreateTextFile(strPath, True)

‘ Next section creates the file to store Events
‘ Then creates WMI connector to the Logs

Set objWMI = GetObject("winmgmts:" _
& strComputer & "\root\cimv2")
Set colLoggedEvents = objWMI.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = ‘System’" )

Wscript.Echo " Press OK and Wait 30 seconds (ish)"
‘ —————————————–
‘ Next section loops through ID properties
intEvent = 1
For Each objEvent in colLoggedEvents
If objEvent.EventCode = intNumberID Then

strFile.WriteLine ("Record No: ")& intEvent
‘ strFile.WriteLine ("Category: " & objEvent.Category)
strFile.WriteLine ("Computer Name: " & objEvent.ComputerName)
strFile.WriteLine ("Event Code: " & objEvent.EventCode)
‘ strFile.WriteLine ("Message: " & objEvent.Message)
‘ strFile.WriteLine ("Record Number: " & objEvent.RecordNumber)
strFile.WriteLine ("Source Name: " & objEvent.SourceName)
‘ strFile.WriteLine ("Time Written: " & objEvent.TimeWritten)
strFile.WriteLine ("Event Type: " & objEvent.Type)
strFile.WriteLine ("User: " & objEvent.User)
strFile.WriteLine (" ")
intRecordNum = intRecordNum +1
End if
IntEvent = intEvent +1
Wscript.Echo "Check " & strPath & " for " &intRecordNum & " events"


‘ End of Guy’s Script


See More Windows Update Error Codes 8004 Series

Error 80004005 Unspecified Error   •Error 80041021   •Error 80041001   •Error 80041002

Error 80048820   •Error 8004100E   •Review of SolarWinds Application Monitor (SAM)

Error 80040E14   • Error 80040E37   • Error 80041006   • Error 80041006

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