Computer Performance, Windows 2003, Exchange 2003, Logon Scripts

Code 80041021 - Error 0x80041021

Troubleshooting Code 80041021 - Error 0x80041021

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.

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

Wrong
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}!\\" _

Example of Code Error 80041021 Script

Mistake in Line 38

Set objWMI = GetObject("winmgmts:"

Correction:

Set objWMI = GetObject("winmgmts:\\"

 

 

' EventID12.vbs
' Version 1.9
' Guy Thomas 1st August 2004

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)
Else
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
Next
Wscript.Echo "Check " & strPath & " for " &intRecordNum & " events"

WScript.Quit

' End of Guy's Script

Solarwinds IpMonitorTry a different solution, download SolarWinds ipMonitor

Here is my thinking, ipMonitor will give you valuable data about your network and servers.  This extra information just may unlock the solution to your error code.  One more thing, sometimes when troubleshooting you go around in circles; therefore if you try a different, but related approach, you may just crack the problem.  Free Download of SolarWinds ipMonitor

Computer Training Software - Recommended Training VideosGuy Thomas recommends Computer Training Software

Their topics and material are ideal for getting you started with VBScript.  The videos are easy to follow and you can control the pace.  Try their free demo material and then see if you want to buy the full package. See more about VB Script Training CD.


Do you need extra help?

For interpreting the WSH messages check Diagnose 800 errors.

For general advice try my 7 Troubleshooting techniques

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:

 *


Google

Webcomputerperformance.co.uk

GFi Events Manager

Guy Recommends: GFi EventsManager

Here is a solution to monitor, manage and archive thousands of events that are generated by devices across your entire network.  Get your free evaluation copy of GFI EventsManager.

 

Home Copyright © 1999-2008 Computer Performance LTD All rights reserved

Please report a broken link, or an error.